Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

pthreads linking error #1

Open
tims opened this Issue · 2 comments

2 participants

Tim Sell MOHAMED-ALI
Tim Sell

On ubuntu 9.04. I went through building playdar etc etc, right debs and such.
During the make stage, I getting linking errors building main.cpp.

[100%] Building CXX object CMakeFiles/f2f-demo.dir/app/main.cpp.o
/usr/bin/c++    -I/home/tims/workspace/playdar/tmp/libf2f/include   -Wall -g -fno-operator-names -fPIC -O2 -o CMakeFiles/f2f-demo.dir/app/main.cpp.o -c /home/tims/workspace/playdar/tmp/libf2f/app/main.cpp
Linking CXX executable ../bin/f2f-demo
/usr/bin/cmake -E cmake_link_script CMakeFiles/f2f-demo.dir/link.txt --verbose=1
/usr/bin/c++      CMakeFiles/f2f-demo.dir/app/main.cpp.o  -o ../bin/f2f-demo -rdynamic -L/home/tims/workspace/playdar/tmp/libf2f/lib -L/usr/local/lib libf2f.a -Wl,-Bstatic -lboost_filesystem-mt -lboost_system-mt -lboost_regex-mt -lboost_thread-mt -lboost_program_options-mt -lboost_date_time-mt -Wl,-Bdynamic -Wl,-rpath,/home/tims/workspace/playdar/tmp/libf2f/lib:/usr/local/lib
CMakeFiles/f2f-demo.dir/app/main.cpp.o: In function `posix_tss_ptr':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create'
CMakeFiles/f2f-demo.dir/app/main.cpp.o: In function `~posix_tss_ptr':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete'
CMakeFiles/f2f-demo.dir/app/main.cpp.o: In function `~posix_thread':
/usr/include/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach'
CMakeFiles/f2f-demo.dir/app/main.cpp.o: In function `boost::asio::detail::posix_thread::join()':
/usr/include/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join'
CMakeFiles/f2f-demo.dir/app/main.cpp.o: In function `posix_signal_blocker':
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:48: undefined reference to `pthread_sigmask'
CMakeFiles/f2f-demo.dir/app/main.cpp.o: In function `~posix_signal_blocker':
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:55: undefined reference to `pthread_sigmask'
Tim Sell

I got it to work by adding -pthread to the gcc arguments:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a388531..c9389aa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,9 @@ SET(SRC "${F2F_PATH}/src")
 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${F2F_PATH}/bin")
 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${F2F_PATH}/lib")
 
+# On ubuntu 9.04, I needed this or I got complaints about unable to link to pthreads. ~Tims
+set(CMAKE_CXX_FLAGS "-pthread")
+
 # binaries get installed here
 SET(CMAKE_INSTALL_PREFIX "/usr/local/")
MOHAMED-ALI

The answer ahead is correct and also if you want to append into your CMAKE_CXX_FLAGS (not reset) you can do this also:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.