libpthread.so.0: error adding symbols: DSO missing from command line

前端 未结 14 1023
长情又很酷
长情又很酷 2020-11-22 07:00

When I\'m compiling openvswitch-1.5.0, I\'ve encountered the following compile error:

 gcc -Wstrict-prototypes -Wall -Wno-sign-compare -Wpointer-arith
     -         


        
14条回答
  •  礼貌的吻别
    2020-11-22 07:17

    If you are using CMake, there are some ways that you could solve it:

    Solution 1: The most elegant one

    add_executable(...)
    target_include_directories(...)
    target_link_libraries(target_name pthread)
    

    Solution 2: using CMake find_package

    find_package(Threads REQUIRED) # this will generate the flag for CMAKE_THREAD_LIBS_INIT
    
    add_executable(...)
    target_include_directories(...)
    target_link_libraries(target_name ${CMAKE_THREAD_LIBS_INIT})
    

    Solution 3: Change CMake flags

    # e.g. with C++ 17, change to other version if you need
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread")
    

提交回复
热议问题