gpt4 book ai didi

c++ - 无法编译任何 C++ 程序;错误 : unknown type name 'uint8_t'

转载 作者:可可西里 更新时间:2023-11-01 15:51:49 29 4
gpt4 key购买 nike

EDIT2:问题是不是简单的打印错误。我在下面的日志中打错了字,我更正了,但问题仍然存在。

编辑:在下面尝试之后,我错误地使用 gcc 而不是 g++ 运行了一次。问题在 g++ 之前就存在,现在也存在。

我目前使用的是 MacOS High Sierra 机器。我最近将很多文件从 MacBook Air 移到了这台机器上,包括我认为都是 Xcode 的垃圾。现在,当我尝试编译一个非常简单的 C++ 程序时:

#include <iostream>

int main()
{
// VAR_DEC
int a = 4;
// VAR_MANIP
a = a*2;
// VAR_PRINT
std::cout << a << std::endl;
return 0;
}

我收到以下荒谬的错误:

jrfarah@Josephs-MBP: [config_file_script] $ g++ test.cpp -o test
In file included from test.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:470:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view:171:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string:56:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:640:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:629:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/typeinfo:61:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/exception:82:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:86:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
/usr/include/sys/resource.h:196:2: error: unknown type name 'uint8_t'
uint8_t ri_uuid[16];
^
/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
uint64_t ri_user_time;
^
/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
uint64_t ri_system_time;
^
/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
uint64_t ri_pkg_idle_wkups;
^
/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
uint64_t ri_interrupt_wkups;
^
/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
uint64_t ri_pageins;
^
/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
uint64_t ri_wired_size;
^
/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
uint64_t ri_resident_size;
^
/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
uint64_t ri_phys_footprint;
^
/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
uint64_t ri_proc_start_abstime;
^
/usr/include/sys/resource.h:206:2: error: unknown type name 'uint64_t'
uint64_t ri_proc_exit_abstime;
^
/usr/include/sys/resource.h:210:2: error: unknown type name 'uint8_t'
uint8_t ri_uuid[16];
^
/usr/include/sys/resource.h:211:2: error: unknown type name 'uint64_t'
uint64_t ri_user_time;
^
/usr/include/sys/resource.h:212:2: error: unknown type name 'uint64_t'
uint64_t ri_system_time;
^
/usr/include/sys/resource.h:213:2: error: unknown type name 'uint64_t'
uint64_t ri_pkg_idle_wkups;
^
/usr/include/sys/resource.h:214:2: error: unknown type name 'uint64_t'
uint64_t ri_interrupt_wkups;
^
/usr/include/sys/resource.h:215:2: error: unknown type name 'uint64_t'
uint64_t ri_pageins;
^
/usr/include/sys/resource.h:216:2: error: unknown type name 'uint64_t'
uint64_t ri_wired_size;
^
/usr/include/sys/resource.h:217:2: error: unknown type name 'uint64_t'
uint64_t ri_resident_size;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

我已经尝试安装和重新安装所有我能想到的与该问题相关的东西,例如 gccg++ccbrew、Xcode、command-line-tools 等。我还尝试了以下页面上的所有建议:

等等,但这些总结得很好。没有一种解决方案有效。

我认为the last one有最可能的解决方案。 (如果您在页面上搜索“未知”,您将看到修复程序。)根据开发人员的说法:

Fix: Remove /opt/local/include/** and /opt/local/lib/** from the "Header Search Paths" build settings. Replace them with much more specific paths to the desired include directories. In my particular case, this meant replacing them with /opt/local/include/glib-2.0 /opt/local/lib/glib-2.0/include /opt/local/include/. It's up and running again!

但是,我没有安装Xcode,我只安装了命令行开发者工具。因此,我没有访问“Header Search Paths”build设置的简单方法,因此,我无法尝试他的解决方案。

我正在寻找解决此问题的方法,最好是不需要我安装整个操作系统的方法。或者,如果有人可以指导我找到build设置文件,我将不胜感激。

最佳答案

也许你可以试试:

mv/usr/local/include/usr/local/include.old

然后:

brew install llvm

关于c++ - 无法编译任何 C++ 程序;错误 : unknown type name 'uint8_t' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48029309/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com