Sha*_*cks 3 c++ std multiple-inclusions include-path clang++
所以我在 mac 上想要尝试最新的 llvm 版本,而不必等待它们在 xcode 命令行工具上传递。
因此,我从他们的下载页面下载了 LLVM 10 版本的预构建二进制文件,并将其放在名为 llvm 的文件夹中。因此,可以在 ~/SDKs/LLVM/bin 中找到 clang 可执行文件。
我制作这个程序:
#include <string>
#include <iostream>
int main(int argc, char const *argv[])
{
std::string myString("Hello World");
std::cout << myString;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并运行:
~/SDKs/Clang+LLVM10/bin/clang++ main.cpp
Run Code Online (Sandbox Code Playgroud)
我收到这个致命错误:
~/SDKs/Clang+LLVM10/bin/../include/c++/v1/string.h:60:15: fatal error:
'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
这没有意义,因为我可以使用 finder 手动找到 string.h,并且它就在错误中引用的文件夹中。
我猜这与 clang++ 首先搜索我的系统包含路径有关,在那里找到旧的 string.h ,因此选择不使用更新的 string.h ,从而导致错误?
一些附加信息(如果有帮助的话):
运行这个(新编译器)
~/Programming/SDKs/Clang+LLVM10/bin/clang++ -Wp,-v -E -xc -x c++ /dev/null
Run Code Online (Sandbox Code Playgroud)
给我:
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
~/SDKs/Clang+LLVM10/bin/../include/c++/v1
/usr/local/include
~/SDKs/Clang+LLVM10/lib/clang/10.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
# 1 "/dev/null"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 393 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/dev/null" 2
Run Code Online (Sandbox Code Playgroud)
运行(这是我的 mac 自带的默认编译器)
clang++ -Wp,-v -E -xc -x c++ /dev/null
Run Code Online (Sandbox Code Playgroud)
给我
clang -cc1 version 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "/dev/null"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 374 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/dev/null" 2
Run Code Online (Sandbox Code Playgroud)
小智 10
我也遇到了这个错误。经过我的挖掘,我找到了原因: \ninclude_next 是一个 gnu 编译器扩展,似乎在 clang 中不存在。虽然 clang(/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++) 已将原始 std lib 打包在目录下:\n\xe2\x80\x9c /Applications/Xcode.app/ Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/\xe2\x80\x9c,但在Apple Mac编译源代码时,一般都是通过选项\xe2\x80\x9c指定系统根路径-isysroot\xe2\x80\x9d,一般命令是这样的:\xe2\x80\x9c-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk \xe2\x80\x9d\n,覆盖默认的 std lib 搜索路径。\n因此,也许您必须覆盖默认的 sys 根目录以确保链接正确的 std lib。
\n