Skip to content

cmake fails to generate makefiles #478

@iam

Description

@iam

Running this command on some Ubuntu systems:

cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ../CMake

(from README.md "Linux --- Clang" instructions)

Gives the following error message:

    "/usr/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /mnt/ssd3/workspace/github/iam/rxcpp/projects/build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/make" "cmTC_861e7/fast"
    /usr/bin/make -f CMakeFiles/cmTC_861e7.dir/build.make CMakeFiles/cmTC_861e7.dir/build
    make[1]: Entering directory '/mnt/ssd3/workspace/github/iam/rxcpp/projects/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_861e7.dir/testCXXCompiler.cxx.o
    /usr/bin/clang++     -o CMakeFiles/cmTC_861e7.dir/testCXXCompiler.cxx.o -c /mnt/ssd3/workspace/github/iam/rxcpp/projects/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_861e7
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_861e7.dir/link.txt --verbose=1
    /usr/bin/clang++       -rdynamic CMakeFiles/cmTC_861e7.dir/testCXXCompiler.cxx.o  -o cmTC_861e7 
    /usr/bin/ld: cannot find -lstdc++
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    CMakeFiles/cmTC_861e7.dir/build.make:97: recipe for target 'cmTC_861e7' failed
    make[1]: *** [cmTC_861e7] Error 1
    make[1]: Leaving directory '/mnt/ssd3/workspace/github/iam/rxcpp/projects/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_861e7/fast' failed
    make: *** [cmTC_861e7/fast] Error 2

The fix appears to be to append -DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++" to the above cmake command line.

Interestingly enough, projects/CMake/shared.cmake already adds that flag, but it seems that the file is included too late for the test cmake program to succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions