1

I'm writing a single threaded application. I use CMake to compile it. My application is being written in C++ using Boost. When run 'make' linking of my application fails with following error message:

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

This is the error itself:

 undefined reference to symbol 'pthread_rwlock_unlock@@GLIBC_2.2.5'

My CMakeLists.txt from the src directory is following:

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)

How do I tell CMake and Boost that I do not pthreads at all and I want single threaded version to be compiled?

Gabriel
  • 763
  • 1
  • 10
  • 28
mcsim
  • 1,647
  • 2
  • 16
  • 35
  • How is CMake relevant here and can you compile successfully from the commandline? Is your Boost library perhaps not available in a single-threaded version (use `ldd` to find dependencies)? Also, what gains do you expect from a single-threaded version? – Ulrich Eckhardt Jul 26 '15 at 19:56
  • Try building boost with `threading=single`. – Igor R. Jul 26 '15 at 20:54
  • @UlrichEckhardt I turned out that I have the same problem, when I compile from the command line. So, probably you're right cmake could be irrelevant here. I want single-threaded version, because I'm sure that I will not need thread safety, because my application is always going to be single threaded. – mcsim Jul 27 '15 at 09:00

1 Answers1

2

According to the FindBoost documentation page, you need to use

Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded libraries ('mt' tag). Default is ON.

Set this before calling find_package(Boost). In my answer to Linking boost library with Boost_USE_STATIC_LIB OFF on Windows I show details on how I have built against boost using cmake. The relevant part to answer your question is

set(Boost_USE_MULTITHREADED OFF)
find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )

When using makefiles, I often find it helpful to use make VERBOSE=1 to see exactly what commands the make system is invoking.

Community
  • 1
  • 1
Phil
  • 5,822
  • 2
  • 31
  • 60