【问题标题】:clang++ installed via homebrew (macOS): compilation errors通过自制软件(macOS)安装的 clang++:编译错误
【发布时间】:2019-03-08 19:21:09
【问题描述】:

安装 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 的版本,我们甚至不知道它到底是哪个版本的 LLVM...

【问题讨论】:

  • 在 Mac OS X 上,您通常会得到 clang 作为 XCode 的一部分。您从自制软件中尝试的任何具体原因?
  • @bobah Xcode 附带了哪个 clang 版本? Apple LLVM version 10.0.0 (clang-1000.11.45.2) 对我们来说意义不大,不是吗?我想尝试某些 C++17 或 C++2a 功能,并且想知道我正在使用的确切 clang 版本。
  • @boobah 向下滚动。这篇文章中的解决方案不再起作用;)
  • 该死!但我仍然会尝试__cplusplus 和基于每个功能宏的代码内测试方法,如果只是尝试反对使用“本机”编译器的“外星人”构建感染 Mac(我将 brew 用于除了 clang 本身之外的所有内容)。

标签: c++ macos llvm homebrew clang++


【解决方案1】:

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

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

xcrun --show-sdk-path

release notes

命令行工具包在 macOS SDK 中安装 macOS 系统头文件。使用已安装工具编译的软件将在以下任一 Xcode 提供的 macOS SDK 中搜索标头:

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

或命令行工具:

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

取决于使用 xcode-select 选择哪个。

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

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

另见:https://github.com/Homebrew/homebrew-core/issues/32765

【讨论】:

  • 此答案中最重要的部分之一是您需要使用-isysroot 而不是-I
【解决方案2】:

我可以在 clang++ 命令行中添加一个 -I(减去眼睛)选项,指向 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14。 sdk/usr/include

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-25
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多