CMake "clang ++ cannot compile simple test program" (Fedora 20)

So I tried to install clang + cmake to compile a simple C ++ program and I get the following error:

-- 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

      

It doesn't even compile my program because it fails to compile the test program.

Looks like an important line:

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

      

However, I have verified that it is libstdc++

installed and updated, so at this point I am completely lost.

Other things I've tried:

  • Using prebuilt binaries instead sudo yum install clang

  • uninstall and reinstall
  • Tried it clang++ hello.cpp

    (hello world program). He says he was <iostreams>

    not found. Is clang the missing standard library? EDIT: Going to is <iostream>

    giving me the same linker error above.

I'm not familiar with the clang scene, cmake and C ++ in general, so I would appreciate any pointers. Thank!

+3


source to share


2 answers


You need development libraries and headers for C ++ library, try



yum install libstdc++-devel

      

+2


source


It seems that your / home / gnu / bin / C ++ requires an extra flag to reference things correctly, and CMake is unaware of this.

To use / usr / bin / C ++ how your compiler runs cmake with -DCMAKE_CXX_COMPILER = / usr / bin / C ++.



In addition, the variable CMAKE_PREFIX_PATH sets the target directory where the project files should be installed. It has nothing to do with the CMake installation prefix, and CMake itself already knows this.

-1


source







All Articles