Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthreads linking error #1

Open
tims opened this issue Jul 11, 2009 · 2 comments
Open

pthreads linking error #1

tims opened this issue Jul 11, 2009 · 2 comments

Comments

@tims
Copy link

tims commented Jul 11, 2009

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'
@tims
Copy link
Author

tims commented Jul 11, 2009

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/")

@saidmohamedali
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants