我正在尝试使用 g++11.3 在 Ubuntu 的 WSL 2 上使用 CMake 构建我的项目(但我可以看到编译器版本不是这里的问题)。各种源文件中有几个编译错误:
/usr/local/include/__config:13:10: fatal error: __config_site: No such file or directory
13 | #include <__config_site>
|
我发现文件
__config_site.in
存在,但不知何故对编译器不可见。我完全不知道这里的根本原因是什么。你知道如何修复它吗?预先感谢!
编辑:
在这样的最小示例中也会出现错误:
主.cpp
#include <algorithm> // e.g. this header makes error
int main() {
}
CMakeLists.txt
project(Test)
set(CMAKE_CXX_STANDARD 20)
add_executable(Test main.cpp)
完整的错误堆栈跟踪: 在这种情况下:
In file included from /usr/local/include/stdlib.h:87,
from /usr/include/c++/11/cstdlib:75,
from /usr/include/c++/11/bits/stl_algo.h:59,
from /usr/include/c++/11/algorithm:62,
from main.cpp:1:
/usr/local/include/__config:13:10: fatal error: __config_site: No such file or directory
13 | #include <__config_site>
|
基本上对我有用的是:
cp -avp \
$(find /opt/git/llvm-project/build -iname "*__config_site*") \
/opt/local/include/c++/v1/
$ clang++ --version
clang version 18.1.0rc (https://github.com/llvm/llvm-project.git 6d8f9290b6afa5e61841124ae1bdeb96d9ada820)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/local/bin
并这样编译:
clang++ \
-std=c++20 \
-nostdinc++ -nostdlib++ \
-isystem /opt/local/include/c++/v1/ \
-L /opt/local/lib/ \
-Wl,-rpath,/opt/local/lib \
-lc++ -lfmt -pthread \
-o /tmp/main.run /tmp/main.cc
显然,如果您在
/opt/local/
之外的其他地方安装了 clang,请调整您的路径。 (我听说有传言说它甚至可以在 build
目录中工作......)