【问题标题】:Cannot compile any C++ programs; error: unknown type name 'uint8_t'无法编译任何 C++ 程序;错误:未知类型名称'uint8_t'
【发布时间】:2018-06-10 06:58:04
【问题描述】:

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 最有可能的解决方案。 (如果您在页面上搜索“未知”,您将看到修复。)根据开发人员的说法:

修复:从“标题搜索路径”构建设置中删除 /opt/local/include/** 和 /opt/local/lib/**。将它们替换为所需包含目录的更具体的路径。在我的特殊情况下,这意味着用 /opt/local/include/glib-2.0 /opt/local/lib/glib-2.0/include /opt/local/include/ 替换它们。它再次启动并运行!

但是,我没有安装 Xcode,我只安装了命令行开发者工具。因此,我没有一种简单的方法来访问“标题搜索路径”构建设置,因此,我无法尝试他的解决方案。

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

【问题讨论】:

标签: c++ xcode macos homebrew


【解决方案1】:

也许你可以试试:

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

然后:

brew install llvm

【讨论】:

  • 这个解决方案对我有用。该问题发生在从另一台笔记本电脑迁移后,重新安装 xcode/devtools 不起作用,任何其他建议的解决方案也没有。虽然这不是公认的答案,但它要简单得多。我建议你 mv /usr/local/include ~/include.old 而不是 rm.
【解决方案2】:

很明显,您的系统 GCC 安装失败了。请注意,GCC 是编译器的套件,而 G++ 是 C++ 前端。包管理器通常有一个名为gcc-g++ 的单独包,但是,从源代码编译时,您只需执行--enable-languages=c,c++。现在,如果重新安装 XCode 不能解决问题(你应该已经这样做了,如果“它占用了太多空间”就删除它),那么你可以尝试从源代码编译 GCC。改编自GNU wiki

  • 首先,从here获取所需的 GCC tar 球

  • tar zxvf gcc*解压

  • cd gcc* 然后./contrib/download_prerequisites

  • 进行源外构建:mkdir build &amp;&amp; cd build

  • ../gcc*/configure --prefix=$HOME/gcc-install --enable-languages=c,c++

  • makemake install

现在只需将$HOME/gcc-install/bin 添加到您的路径中,您就可以开始了。

【讨论】:

  • 这解决了我的问题!我还想补充一点,在尝试此操作之前,我必须手动删除命令行工具目录手动;除此之外,这行得通!谢啦!另外,我希望我可以两次投票支持“borked”这个词的原始用法。
  • 什么有效?你不可能这么快编译 GCC。
  • 这些通常是我用来解决问题的步骤——从源代码编译 GCC 并将其添加到我的路径中。我遇到了一些小问题——这就是为什么我没有发布类似答案的原因——但我已经将问题缩小到之前安装的 ROOT,并且我一直在努力解决这个问题最后几个小时。如有任何混淆,请见谅!
  • 我想再次确认您的回答完全有效。我最近不得不在同事的计算机上解决类似的问题,并按照您的确切步骤解决了它。显然,仅在我的机器上需要手动删除 command-line-tools 目录。再次感谢您的帮助!
【解决方案3】:

我在从源代码编译 Perl-5.34.0 时遇到了这个错误。对我有用的另一种解决方案是设置 SDK 环境变量:

export SDK=`xcrun --show-sdk-path`

有时,您可能需要以同样的方式设置SDKROOT

export SDKROOT=`xcrun --show-sdk-path`

将其放入您的 ~/.profile 文件中将(方便地)使此设置永久化。

【讨论】:

    猜你喜欢
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    • 2017-12-24
    • 1970-01-01
    • 2014-12-12
    • 2015-10-20
    • 2018-05-14
    相关资源
    最近更新 更多