MantisBT - CMake
View Issue Details
0015510CMakeCMakepublic2015-04-13 03:072015-11-02 09:13
nickdesaulniers 
Nils Gladitz 
normalminoralways
closedno change required 
x86-64LinuxUbuntu 15.04
CMake 3.0.2 
 
0015510: After 15.04 upgrade, cannot link against against pthread using C++11 <thread>
So I recently upgraded my headless server from 14.04 to 15.04 using `sudo do-release-upgrade -d`. After the upgrade, I had to reinstall boost, but one of my projects that I build with cmake stopped building.

➜ build git:(master) ✗ make
Scanning dependencies of target main
[ 33%] Building CXX object CMakeFiles/main.dir/hello.cpp.o
[ 66%] Building CXX object CMakeFiles/main.dir/packet.cpp.o
[100%] Building CXX object CMakeFiles/main.dir/key_value_store.cpp.o
Linking CXX executable main
/usr/bin/ld: CMakeFiles/main.dir/hello.cpp.o: undefined reference to symbol 'pthread_create@@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
CMakeFiles/main.dir/build.make:136: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

I had to explicitly link against pthread to have <thread> support for C++11, when prior to my upgrade to 15.04, I did not have to. Not sure if this is cmake related or not.
git checkout https://github.com/nickdesaulniers/cpp11-memcached.git [^]
cd cpp11-memcached
git checkout b419bd
mkdir build
cd build
cmake ..
make
Originally posted here: http://ubuntuforums.org/showthread.php?t=2273365 [^]

Not sure if there's some incompatibility between cmake and new versions of Ubuntu, or if I have a botched upgrade. It's just odd that this used to work without this patch: https://github.com/nickdesaulniers/cpp11-memcached/commit/4ce7505335c59754033b3c90409be050eb48d134 [^]
No tags attached.
related to 0010692closed Philip Lowman FindBoost fails to add -lpthread 
Issue History
2015-04-13 03:07nickdesaulniersNew Issue
2015-04-13 03:15Nils GladitzRelationship addedrelated to 0010692
2015-04-13 04:08Nils GladitzNote Added: 0038488
2015-04-13 12:55nickdesaulniersNote Added: 0038495
2015-04-13 13:03Nils GladitzNote Added: 0038497
2015-04-13 13:18nickdesaulniersNote Added: 0038500
2015-04-13 13:20Nils GladitzNote Added: 0038501
2015-04-13 13:20Nils GladitzStatusnew => resolved
2015-04-13 13:20Nils GladitzResolutionopen => no change required
2015-04-13 13:20Nils GladitzAssigned To => Nils Gladitz
2015-11-02 09:13Robert MaynardNote Added: 0039766
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0038488)
Nils Gladitz   
2015-04-13 04:08   
gcc requires you to link the thread library when using <thread> [1].
What seems to have changed in gcc is that this is diagnosed at link rather than runtime [2].

CMake itself provides the FindThreads.cmake [3] module which should pick up the appropriate thread library.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52681 [^]
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61841 [^]
[3] http://www.cmake.org/cmake/help/v3.2/module/FindThreads.html [^]
(0038495)
nickdesaulniers   
2015-04-13 12:55   
Hey Nils, thanks for the info!

It's possible that I was previously able to build but that I did not run on linux to verify, and that I have upgraded my version of gcc.

How do cmake modules work? What's the syntax? There doesn't seem to be information on this in the docs.

I don't think that my current patch is portable to windows, for example.
https://github.com/nickdesaulniers/cpp11-memcached/commit/4ce7505335c59754033b3c90409be050eb48d134 [^]
(0038497)
Nils Gladitz   
2015-04-13 13:03   
I suppose it may even have run (rather than just build) before if the thread library has been loaded through an indirect dependency (e.g. you link to a library which itself depends on the thread library).

Find modules are used with find_package() [1].

e.g.
  find_package(Threads REQUIRED)
  target_link_libraries(main ${CMAKE_THREAD_LIBS_INIT})

[1] http://www.cmake.org/cmake/help/v3.2/command/find_package.html [^]
(0038500)
nickdesaulniers   
2015-04-13 13:18   
indeed, my code blocks on accepting a tcp connection, then spawns a thread: https://github.com/nickdesaulniers/cpp11-memcached/blob/master/hello.cpp#L40-L41 [^]

So I would have built and run on linux, but not actually tested with connections.

Thank you for the info, I assume we can close this ticket as not a bug?
(0038501)
Nils Gladitz   
2015-04-13 13:20   
Done :)
(0039766)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.