升级到Mojave后,无法使用`#include`编译C ++'hello world' [英] Can't compile C++ 'hello world' with `#include` after upgrading to Mojave

查看:86
本文介绍了升级到Mojave后,无法使用`#include`编译C ++'hello world'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CS学生,在升级到Mojave之前,编译效果很好.这样做之后,如果它具有include陈述,我将无法工作.例如:

CS student, compiling worked fine before upgrading to Mojave. After doing so I cannot get anything to work if it has an include statment. For example:

#include <iostream>
int main()
{
    std::cout << "length:" << 10 << std::endl;

    return 0;
}

编译时:

$ g++ -ferror-limit=3 main2.cpp -o test
In file included from main2.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:477:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:203:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:158:8: error: no member named 'uint8_t' in the global
      namespace
using::uint8_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:159:8: error: no member named 'uint16_t' in the global
      namespace
using::uint16_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:160:8: error: no member named 'uint32_t' in the global
      namespace
using::uint32_t;
     ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
4 errors generated.

我有

  • 已安装Xcode 10
  • 安装了最新的开发人员命令行工具
  • 我使用的是gcc 8.2(最新的Brew提供)
  • 遵循了建议的此处,其中包括正在运行...

  • Installed Xcode 10
  • Installed the latest developer command line tools
  • I am on gcc 8.2 (the latest brew provides)
  • followed the suggestions here, which included running...

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

  • 多次重启计算机

  • Restarted computer many times

    没有主意.从Xcode编译c ++直接起作用.但是从命令行g ++反复失败.不确定下一步要去哪里.

    Out of ideas. Compiling c++ from Xcode directly worked. But from command line g++ fails repeatedly. Not sure where to go next.

    如果有相关要求,请参阅MacBook Pro 15,2018.MacOS 10.14.0.

    If relevant this is on MacBook Pro 15", 2018. MacOS 10.14.0.

    感谢任何人的时间.

    此处我可以使用

    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
    

    我的g++通话中的

    标志.

    flag in my g++ calls.

    我当然不需要永远这样做.

    Of course I don't want to need to do this forever.

    我已经完全删除了Xcode 10和devtools,重新安装它们后问题仍然存在.

    I have COMPLETELY removed Xcode 10 and devtools, and after reinstalling them the issue persists.

    我在这里还应该做什么?它只会对我有什么影响?

    What else should I do here? How would it affect only me?

    最终重新安装了操作系统以解决问题.对于知道钉子有多大的人来说,这是个很大的锤子,但它确实有用.

    Ended up reinstalling OS to solve issue. Was a big hammer for who knows how big of a nail, but it worked.

    推荐答案

    我遇到了同样的问题.

    我在/Applications/.../MacOSX10.14.sdk/usr/include中安装了标题.我没有将g ++调用别名为始终使用-isysroot,而是将/Applications/.../MacOSX10.14.sdk/usr/include添加到了

    I had the headers installed in /Applications/.../MacOSX10.14.sdk/usr/include. Instead of aliasing my g++ calls to always use -isysroot, I added /Applications/.../MacOSX10.14.sdk/usr/include to my CPLUS_INCLUDE_PATH.

    我使用并添加到.bash_profile中的确切代码行是

    The exact line of code I used and added to my .bash_profile was

    export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
    

    我觉得这是一个更优雅的解决方案,因为据我了解,使用 isysrootsysroot 会告诉g ++不要在默认位置搜索,这时您可能需要同时包含Mac SDK目录和通常的/usr/include/usr/local/include等.

    I feel that this is a more elegant solution, since from what I understand using isysroot or sysroot will tell g++ to not search in the default places, when you may need includes from both the mac SDK directory and the usual /usr/include, /usr/local/include, and so on.

    这篇关于升级到Mojave后,无法使用`#include`编译C ++'hello world'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆