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;
}
또한 gcc로 잘 컴파일되는 cmake/c++ 프로젝트가 있지만 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