c++ - CMake "clang++ is not able compile a simple test program"(软呢帽 20)

标签 c++ cmake clang fedora

所以我尝试安装 clang + cmake 来编译一个简单的 C++ 程序,但出现以下错误:

-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/clang++
-- Check for working CXX compiler: /usr/local/bin/clang++ -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCXXCompiler.cmake:54 (message):
  The C++ compiler "/usr/local/bin/clang++" is not able to compile a simple
  test program.

  It fails with the following output:

   Change Dir: /home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp



  Run Build Command:/usr/bin/gmake "cmTryCompileExec697180971/fast"

  /usr/bin/gmake -f CMakeFiles/cmTryCompileExec697180971.dir/build.make
  CMakeFiles/cmTryCompileExec697180971.dir/build

  gmake[1]: Entering directory
  `/home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp'

  /usr/bin/cmake -E cmake_progress_report
  /home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp/CMakeFiles 1

  Building CXX object
  CMakeFiles/cmTryCompileExec697180971.dir/testCXXCompiler.cxx.o

  /usr/local/bin/clang++ -o
  CMakeFiles/cmTryCompileExec697180971.dir/testCXXCompiler.cxx.o -c
  /home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

  Linking CXX executable cmTryCompileExec697180971

  /usr/bin/cmake -E cmake_link_script
  CMakeFiles/cmTryCompileExec697180971.dir/link.txt --verbose=1

  /usr/local/bin/clang++
  CMakeFiles/cmTryCompileExec697180971.dir/testCXXCompiler.cxx.o -o
  cmTryCompileExec697180971 -rdynamic

  /usr/bin/ld: cannot find -lstdc++

  clang: error: linker command failed with exit code 1 (use -v to see
  invocation)

  gmake[1]: Leaving directory
  `/home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp'

  gmake[1]: *** [cmTryCompileExec697180971] Error 1

  gmake: *** [cmTryCompileExec697180971/fast] Error 2

它甚至没有编译我的程序,因为它无法编译测试程序。

看起来重要的一行在这里:

 /usr/bin/ld: cannot find -lstdc++

但是,我检查了libstdc++已安装并且是最新的,所以此时我很迷茫。

我尝试过的其他事情:

  1. 使用预构建的二进制文件而不是 sudo yum install clang
  2. 删除并重新安装
  3. 尝试过 clang++ hello.cpp ( Hello World 程序)。它说<iostreams>没有找到。 clang 缺少标准库吗?编辑:更改为 <iostream>给我上面相同的链接器错误。

我一般不熟悉 clang、cmake 和 C++ 场景,所以我很感激任何指点。谢谢!

最佳答案

你需要C++库的开发库和头文件,试试

yum install libstdc++-devel

关于c++ - CMake "clang++ is not able compile a simple test program"(软呢帽 20),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26380407/

相关文章:

c++ - 为什么函数形参的数组类型转换为指针?

php - 使用 zlib 在 C++ 和 PHP 之间移动压缩字符串

c++ - 如何同步两个程序的定时器

c - 使用 CLion 开发 Arduino 库

c++模板怪异优化

c++ - 有没有办法在父类(super class)构造函数中知道调用对象的子类? C++

c++ - 在 Visual Studio CMake 中设置默认编译器

c++ - 如何在 cmake 中的源文件后设置库标志?

c++ - 为 libclang 全局设置 -D 宏编译器标志

macos - 获取Apple clang版本和对应的上游LLVM版本