How to get CMake to recognize pthread on Ubuntu?

前端 未结 1 344
北海茫月
北海茫月 2020-12-02 18:21

If I compile on the command-line with g++ directly, I can see everything I need is there:

$ g++ -pthread test.cpp
$ ldd a.out
    linux-vdso.so.1 =>  (0x0         


        
相关标签:
1条回答
  • 2020-12-02 19:00

    Oh, this was was a pain! I probably lost 2 hours on this. Here is the solution:

    CMake uses short 'C' applications to test/try things. If the CMakeLists.txt states that C++ is used for the project, without also listing C, then some of those shorts tests incorrectly fail, and cmake then thinks those things aren't found.

    The solution was to change the first line of CMakeLists from this:

    PROJECT ( Test CXX )
    

    ...to include C as a language:

    PROJECT ( Test C CXX )
    

    Then delete build, recreate it, and everything then works:

    rm -rf build
    mkdir build
    cd build
    cmake ..
    
    0 讨论(0)
提交回复
热议问题