xcode 无法编译任何 C++ 程序;错误:未知类型名称“uint8_t”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48029309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot compile any C++ programs; error: unknown type name 'uint8_t'
提问by Joseph Farah
EDIT2: The problem was NOT a simple typographical error. I made a typo in the logs below, which I corrected, but the problem was still there.
EDIT2:问题不是简单的印刷错误。我在下面的日志中打了一个错字,我更正了,但问题仍然存在。
EDIT: I mistakenly ran with gcc instead of g++, once, after attempting below. The problem was there before with g++ and it is there now.
编辑:在尝试以下操作后,我错误地使用 gcc 而不是 g++ 运行一次。问题在 g++ 之前就存在,现在就在那里。
I am currently on a MacOS High Sierra box. I recently moved a lot of files from a MacBook Air to this machine, including what I assume were all of Xcode's junk. Now, when I try to compile a very simple C++ program:
我目前在 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.
I've tried installing and reinstalling everything I could think of related to the problem, such as gcc
, g++
, cc
, brew
, Xcode, command-line-tools
, etc. I've also tried all the suggestions on the following pages:
我已尝试安装和重新安装我能想到的与问题相关的所有内容,例如gcc
、g++
、cc
、brew
、 Xcodecommand-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
- 未知类型名称 uint8_t?
- 在 Mac OS X Yosemite 10.10.1 上包含搜索路径
- 由于未知类型名称“uint64_t”,Cythonizing 失败
- 未知类型名称“uint8_t”,MinGW
- JT Bullitt 非常全面的博客
and more, but those summarize it pretty well. None of the solutions have worked.
还有更多,但这些总结得很好。所有解决方案都没有奏效。
I think the last onehas the most likely solution. (If you search for "unknown" on the page you'll see the fix.) According to the developer:
我认为最后一个最有可能的解决方案。(如果您在页面上搜索“未知”,您将看到修复程序。)根据开发人员的说法:
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!
修复:从“标题搜索路径”构建设置中删除 /opt/local/include/** 和 /opt/local/lib/** 。将它们替换为所需包含目录的更具体的路径。在我的特殊情况下,这意味着将它们替换为 /opt/local/include/glib-2.0 /opt/local/lib/glib-2.0/include /opt/local/include/。它再次启动并运行!
However, I didn't install Xcode, I only installed the command line developer tools. Therefore, I don't have an easy way to access the "Header Search Paths" build settings, and thus, I can't try out his solution.
但是,我没有安装Xcode,我只安装了命令行开发工具。因此,我没有访问“标题搜索路径”构建设置的简单方法,因此,我无法尝试他的解决方案。
I am looking for a solution to this problem, preferably one that doesn't require me installing the entire OS. Alternatively, if someone could kindly guide me through finding the build settings file, I would be very grateful.
我正在寻找解决此问题的方法,最好是不需要我安装整个操作系统的方法。或者,如果有人可以指导我找到构建设置文件,我将不胜感激。
采纳答案by OwO
It's fairly obvious that you borked your system GCC installation. Please note that GCC is a suiteof compilers and that G++is the C++ front-end. Package managers often have a separate package called gcc-g++
, however, when compiling from source, you simply do --enable-languages=c,c++
. Now if reinstalling XCode doesn't resolve the problem (you should've already done this, if "it takes up too much space" just remove it), then you can try compiling GCC from source. Adapted from the GNU wiki:
很明显,您破坏了系统 GCC 安装。请注意,GCC 是一套编译器,而G++是 C++ 前端。包管理器通常有一个单独的包,称为gcc-g++
,但是,从源代码编译时,您只需执行--enable-languages=c,c++
. 现在,如果重新安装 XCode 不能解决问题(您应该已经这样做了,如果“它占用太多空间”只需将其删除),那么您可以尝试从源代码编译 GCC。改编自GNU 维基:
First, grab your desired GCC tar ball from here
Untar it with
tar zxvf gcc*
cd gcc*
then./contrib/download_prerequisites
Do an out of source build:
mkdir build && cd build
../gcc*/configure --prefix=$HOME/gcc-install --enable-languages=c,c++
make
andmake install
首先,从这里获取你想要的 GCC 焦油球
解压它
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
Now just add $HOME/gcc-install/bin
to your path and you should be good to go.
现在只需添加$HOME/gcc-install/bin
到您的路径中,您就可以开始使用了。
回答by Chengcheng Zhang
Maybe you can try:
也许你可以试试:
mv /usr/local/include /usr/local/include.old
mv /usr/local/include /usr/local/include.old
then:
然后:
brew install llvm
brew install llvm