我正在编写一个单线程应用程序。我使用CMake进行编译。我的应用程序是使用Boost使用C ++编写的。当运行'make'时,我的应用程序链接失败,并显示以下错误消息:
Linking CXX executable whisk
cd <project>/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/whisk.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/whisk.dir/driver_simdag.cpp.o CMakeFiles/whisk.dir/whisk.cpp.o CMakeFiles/whisk.dir/driver_miror.cpp.o CMakeFiles/whisk.dir/driver.cpp.o CMakeFiles/whisk.dir/main.cpp.o -o whisk -rdynamic -lboost_program_options
/usr/bin/ld: CMakeFiles/whisk.dir/whisk.cpp.o: undefined reference to symbol 'pthread_rwlock_unlock@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
这是错误本身:
undefined reference to symbol 'pthread_rwlock_unlock@@GLIBC_2.2.5'
我在src目录中的CMakeLists.txt文件如下:
file(GLOB whisk_SRC "[a-zA-Z]*.cpp")
add_executable(whisk ${whisk_SRC})
FIND_PACKAGE( Boost 1.40 COMPONENTS program_options log REQUIRED )
set(Boost_USE_MULTITHREADED OFF)
# set_property(TARGET whisk PROPERTY Boost_USE_MULTITHREADED OFF)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
set_property(TARGET whisk PROPERTY CXX_STANDARD 11)
set_property(TARGET whisk PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(whisk ${Boost_PROGRAM_OPTIONS_LIBRARY})
install(TARGETS whisk DESTINATION bin)
我如何告诉CMake和Boost我根本不使用pthreads,并且我希望编译单线程版本?
根据FindBoost文档页面,您需要使用
Boost_USE_MULTITHREADED-设置为OFF以使用非多线程库(“ mt”标签)。默认为开。
在致电之前进行设置find_package(Boost)
。在我对Windows上将Boost库与Boost_USE_STATIC_LIB OFF链接的答案中,我详细说明了如何使用cmake针对boost进行构建。回答您问题的相关部分是
set(Boost_USE_MULTITHREADED OFF)
find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )
使用makefile时,经常发现使用它make VERBOSE=1
来准确了解make系统正在调用哪些命令是很有帮助的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句