gpt4 book ai didi

c++ - clang++ 通过 Homebrew 软件安装 (macOS) : compilation errors

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:04:43 24 4
gpt4 key购买 nike

安装 clang++(尝试 v.6.0.1 和 7.0)后:
brew install --with-toolchain llvm

非常简单的程序会导致以下错误:

 In file included from test.cpp:1:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iostream:38:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/ios:215:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iosfwd:90:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>

用于编译的命令:

 clang++7() {
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
CPPFLAGS="-I/usr/local/opt/llvm/include"
/usr/local/opt/llvm/bin/clang++ -std=c++11 $CPPFLAGS $LDFLAGS $1
}

是否可以使用官方的clang而不是Apple的版本?
Apple 的版本,我们甚至不知道它到底是哪个版本的 LLVM...

最佳答案

似乎从 Mojave (10.14) 开始,Xcode 不再在 /usr/include 中安装系统头文件。有一个兼容包可以,但不推荐。

相反,官方解决方案是在 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk 中搜索 header 的工具。该路径可以从

xcrun --show-sdk-path

release notes

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:

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

or the Command Line Tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

depending on which is selected using xcode-select.

如果您自己构建了 clang,这可以通过将 -isysroot 选项传递给 clang 来实现:

clang++ -isysroot "$(xcrun --show-sdk-path)" …

另请参阅:https://github.com/Homebrew/homebrew-core/issues/32765

关于c++ - clang++ 通过 Homebrew 软件安装 (macOS) : compilation errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52629110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com