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.
我已尝试安装并重新安装我能想到的与问题相关的所有内容,例如gcc
,g++
,cc
,brew
,Xcode,{{ 1}}等等。我也尝试了以下几页的所有建议:
以及更多,但那些总结得很好。这些解决方案都没有奏效。
我认为the last one最有可能解决方案。 (如果您在页面上搜索“未知”,您将看到修复。)根据开发人员的说法:
修复:从“标题搜索路径”构建设置中删除/ 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”构建设置,因此,我无法尝试他的解决方案。
我正在寻找这个问题的解决方案,最好不要求我安装整个操作系统。或者,如果有人可以指导我找到构建设置文件,我将非常感激。
答案 0 :(得分:11)
也许你可以试试:
mv /usr/local/include /usr/local/include.old
然后:
brew install llvm
答案 1 :(得分:3)
很明显,你搞砸了你的系统GCC安装。请注意,GCC是套件的编译器, G ++ 是C ++的前端。包管理器通常有一个名为gcc-g++
的独立包,但是,从源代码编译时,只需执行--enable-languages=c,c++
。现在,如果重新安装XCode并不能解决问题(你应该已经完成了这个,如果&#34;它占用太多空间&#34;只需删除它),那么你可以尝试从源代码编译GCC 。改编自GNU wiki:
首先,从here
用tar zxvf gcc*
cd gcc*
然后./contrib/download_prerequisites
执行源代码构建:mkdir build && cd build
../gcc*/configure --prefix=$HOME/gcc-install --enable-languages=c,c++
make
和make install
现在只需将$HOME/gcc-install/bin
添加到您的路径中就可以了。
答案 2 :(得分:1)
我在从源代码编译 Perl-5.34.0 时遇到了这个错误。对我有用的替代解决方案是设置 SDK
环境变量:
export SDK=`xcrun --show-sdk-path`
有时,您可能需要以相同的方式设置 SDKROOT
:
export SDKROOT=`xcrun --show-sdk-path`
将其放入您的 ~/.profile
文件将(方便地)使此设置永久化。