编辑2: 问题不是简单的排版错误。我在下面的日志中犯了一个拼写错误,我已经更正了,但问题仍然存在。
编辑:我曾在以下尝试后误运行了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;
}
I get the following ridiculous error:
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.
我已经尝试安装和重新安装与问题相关的所有内容,例如
gcc
,g++
,cc
,brew
,Xcode,command-line-tools
等。我还尝试了以下页面上的所有建议:
- Unknown type name uint8_t?
- Include search path on Mac OS X Yosemite 10.10.1
- Cythonizing fails because of unknown type name 'uint64_t'
- unknown type name 'uint8_t', MinGW
- JT Bullitt's very comprehensive blog
还有更多,但这些总结得很好。没有任何解决方案起作用。
我认为最后一个可能有最可行的解决方案。(如果您在页面上搜索“unknown”,您将看到修复方法。)根据开发人员的说法:
解决方案:从“Header Search Paths”构建设置中删除/opt/local/include/**和/opt/local/lib/**。将它们替换为更具体的路径,以便访问所需的包含目录。在我特定的情况下,这意味着将它们替换为/opt/local/include/glib-2.0 /opt/local/lib/glib-2.0/include /opt/local/include/。现在它可以正常运行了!
但是,我没有安装Xcode,我只安装了命令行开发人员工具。因此,我无法轻松访问“Header Search Paths”构建设置,因此无法尝试他的解决方案。
我正在寻找解决此问题的解决方案,最好不需要我安装整个操作系统。或者,如果有人可以友善地指导我找到构建设置文件,我将非常感激。