如何让VSCode的CMake扩展找到我的C++编译器?

rqmkfv5c  于 12个月前  发布在  Vscode
关注(0)|答案(1)|浏览(118)

我正在VSCode中使用CMake扩展,并试图编译C++代码(在Ubuntu虚拟机上)。编译曾经工作,但突然停止工作,我不知道原因。
在VSCode的CMake扩展中,CMake文件不再出现,当我尝试使用扩展的配置所有项目按钮时,收到以下错误:

[main] Configuring project: zweites-projekt 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -S/home/odin/Schreibtisch/zweites-projekt -B/home/odin/Schreibtisch/zweites-projekt/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is Clang 14.0.0
[cmake] -- The CXX compiler identification is Clang 14.0.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: /usr/bin/clang - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - failed
[cmake] -- Check for working CXX compiler: /usr/bin/clang++
[cmake] -- Check for working CXX compiler: /usr/bin/clang++ - broken
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/odin/Schreibtisch/zweites-projekt/build/CMakeFiles/CMakeOutput.log".
[cmake] See also "/home/odin/Schreibtisch/zweites-projekt/build/CMakeFiles/CMakeError.log".
[cmake] CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
[cmake]   The C++ compiler
[cmake] 
[cmake]     "/usr/bin/clang++"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     Change Dir: /home/odin/Schreibtisch/zweites-projekt/build/CMakeFiles/CMakeTmp
[cmake]     
[cmake]     Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_0d052/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_0d052.dir/build.make CMakeFiles/cmTC_0d052.dir/build
[cmake]     gmake[1]: Verzeichnis „/home/odin/Schreibtisch/zweites-projekt/build/CMakeFiles/CMakeTmp“ wird betreten
[cmake]     Building CXX object CMakeFiles/cmTC_0d052.dir/testCXXCompiler.cxx.o
[cmake]     /usr/bin/clang++    -MD -MT CMakeFiles/cmTC_0d052.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_0d052.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_0d052.dir/testCXXCompiler.cxx.o -c /home/odin/Schreibtisch/zweites-projekt/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
[cmake]     Linking CXX executable cmTC_0d052
[cmake]     /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0d052.dir/link.txt --verbose=1
[cmake]     /usr/bin/clang++ CMakeFiles/cmTC_0d052.dir/testCXXCompiler.cxx.o -o cmTC_0d052 
[cmake]     /usr/bin/ld: -lstdc++ kann nicht gefunden werden: Datei oder Verzeichnis nicht gefunden
[cmake]     clang: error: linker command failed with exit code 1 (use -v to see invocation)
[cmake]     gmake[1]: *** [CMakeFiles/cmTC_0d052.dir/build.make:100: cmTC_0d052] Fehler 1
[cmake]     gmake[1]: Verzeichnis „/home/odin/Schreibtisch/zweites-projekt/build/CMakeFiles/CMakeTmp“ wird verlassen
[cmake]     gmake: *** [Makefile:127: cmTC_0d052/fast] Fehler 2
[cmake]     
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:6 (project)
[cmake] 
[cmake] 
[proc] The command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -S/home/odin/Schreibtisch/zweites-projekt -B/home/odin/Schreibtisch/zweites-projekt/build -G "Unix Makefiles" exited with code: 1

我已经检查了clang是否安装在终端中(在VSCode终端中使用clang --version),并在“C/C编辑配置”下选择了此编译器路径“/usr/bin/clang-14”。
我该怎么解决?

q9rjltbz

q9rjltbz1#

/usr/bin/ld: -lstdc++ kann nicht gefunden werden: Datei oder Verzeichnis nicht gefunden

安装libstdc++-12-dev

sudo apt install libstdc++-12-dev

您可能需要选择9、10、11、12的其他可用版本。

相关问题