无法建立亲爱的

无法建立亲爱的

我尝试在 Ubuntu 22.04.2 LTS 上安装 darling。当我运行以下命令时:

:~/darling/build$ cmake ..

发生了以下错误:

-- 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/faisalmustafa/darling/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_c6302/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_c6302.dir/build.make CMakeFiles/cmTC_c6302.dir/build
    gmake[1]: Entering directory '/home/faisalmustafa/darling/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_c6302.dir/testCXXCompiler.cxx.o
    /usr/bin/clang++    -MD -MT CMakeFiles/cmTC_c6302.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_c6302.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_c6302.dir/testCXXCompiler.cxx.o -c /home/faisalmustafa/darling/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_c6302
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c6302.dir/link.txt --verbose=1
    /usr/bin/clang++ -rdynamic CMakeFiles/cmTC_c6302.dir/testCXXCompiler.cxx.o -o cmTC_c6302 
    /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)
    gmake[1]: *** [CMakeFiles/cmTC_c6302.dir/build.make:100: cmTC_c6302] Error 1
    gmake[1]: Leaving directory '/home/faisalmustafa/darling/build/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:127: cmTC_c6302/fast] Error 2
    
    
  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:44 (project)


-- Configuring incomplete, errors occurred!
See also "/home/faisalmustafa/darling/build/CMakeFiles/CMakeOutput.log".
See also "/home/faisalmustafa/darling/build/CMakeFiles/CMakeError.log". 

您认为我该如何解决这个问题?

非常感谢您的帮助。

答案1

gcc这似乎是当你的系统中存在高于的版本的时出现的问题g++clang++检测并选择最高版本的海湾合作委员会(在您的情况下gcc-12),然后无法链接 g++ 程序,因为/usr/lib/gcc/x86_64-linux-gnu/12/目录缺少相应的 C++ 标准库。

此问题还报告于更新 GCC 后,Clang 无法再找到 libstdc++。我自己在 22.04 上重现了这个错误,其中

$ apt policy gcc g++
gcc:
  Installed: 4:11.2.0-1ubuntu1
  Candidate: 4:11.2.0-1ubuntu1
  Version table:
 *** 4:11.2.0-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        100 /var/lib/dpkg/status
g++:
  Installed: 4:11.2.0-1ubuntu1
  Candidate: 4:11.2.0-1ubuntu1
  Version table:
 *** 4:11.2.0-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        100 /var/lib/dpkg/status

gcc-12显然作为该包的依赖项存在dkms

$ aptitude why gcc-12
i   dkms Depends gcc-12

(可能是因为当前内核是用 gcc-12 构建的?)。因此clang++检测并首选它:

$ clang++ -v -o hello hello.cpp 2>&1 | grep ^Found
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12

我不确定最好的解决方案;较新版本的 clang 提供了一个--gcc 安装目录选项,但在 clang-14 中不存在。似乎可行的一个选项是将 gcc-11 库路径作为链接器选项传递:

clang++ -Wl,-L/usr/lib/gcc/x86_64-linux-gnu/11 -o hello hello.cpp

(或者等效地通过导出LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11到您的构建环境中)。我不太推荐它,因为这样会导致头文件和库之间出现不一致。我想另一个选择是手动安装g++-12在您的系统上。

答案2

你错过了lstdc++。试试sudo apt install libstdc++-11-dev

相关内容