使用 ubuntu 22.04,g++ 可以毫无问题地编译我的测试程序。另一方面,clang++ 会失败......
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "hello world" << endl;
return 0;
}
我还有一个 cmake/c++ 项目,可以用 gcc 很好地编译,但是当我将其重新配置为使用 clang 时,我从 cmake 获得以下输出。
~/C/vkf % cmc && cmake ./ -DCMAKE_BUILD_TYPE=Release -G "Ninja" && ninja
-- The C compiler identification is Clang 14.0.0
-- The CXX compiler identification is Clang 14.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ - broken
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"/usr/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/david/C/vkf/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/ninja cmTC_ef4ce && [1/2] Building CXX object CMakeFiles/cmTC_ef4ce.dir/testCXXCompiler.cxx.o
[2/2] Linking CXX executable cmTC_ef4ce
FAILED: cmTC_ef4ce
: && /usr/bin/clang++ CMakeFiles/cmTC_ef4ce.dir/testCXXCompiler.cxx.o -o cmTC_ef4ce && :
/usr/bin/ld: cannot find -lstdc++: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:11 (project)
-- Configuring incomplete, errors occurred!
See also "/home/david/C/vkf/CMakeFiles/CMakeOutput.log".
See also "/home/david/C/vkf/CMakeFiles/CMakeError.log".
在我的 CMakeError.log 中
/usr/bin/ld: cannot find -lstdc++: No such file or directory
我的系统配置一定发生了一些变化,因为之前这两个都运行正常。有人知道如何修复吗?
答案1
尝试删除cpp-12打包或安装libstdc++-12-dev。
答案2
我通过安装 libc++abi-dev 修复了一个非常类似的问题:
sudo apt install libc++abi-dev