繁体   English   中英

CMake“clang ++无法编译简单的测试程序”(Fedora 20)

[英]CMake “clang++ is not able compile a simple test program” (Fedora 20)

所以我尝试安装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 program)。 它说没有找到<iostreams> clang是否缺少标准库? 编辑:更改为<iostream>在上面给出了相同的链接器错误。

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

您需要C ++库的开发库和标题,请尝试

yum install libstdc++-devel

您的/ home / gnu / bin / c ++似乎需要额外的标记来正确链接事物,而CMake不知道这一点。

使用/ usr / bin / c ++作为编译器使用-DCMAKE_CXX_COMPILER = / usr / bin / c ++运行cmake。

此外,CMAKE_PREFIX_PATH变量设置应安装项目文件的目标目录。 它与CMake安装前缀无关,而CMake本身已经知道这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM