View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015510CMakeCMakepublic2015-04-13 03:072015-11-02 09:13
Reporternickdesaulniers 
Assigned ToNils Gladitz 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
Platformx86-64OSLinuxOS VersionUbuntu 15.04
Product VersionCMake 3.0.2 
Target VersionFixed in Version 
Summary0015510: After 15.04 upgrade, cannot link against against pthread using C++11 <thread>
DescriptionSo 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.
Steps To Reproducegit checkout https://github.com/nickdesaulniers/cpp11-memcached.git [^]
cd cpp11-memcached
git checkout b419bd
mkdir build
cd build
cmake ..
make
Additional InformationOriginally 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 [^]
TagsNo tags attached.
Attached Files

 Relationships
related to 0010692closedPhilip Lowman FindBoost fails to add -lpthread 

  Notes
(0038488)
Nils Gladitz (developer)
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 (reporter)
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 (developer)
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 (reporter)
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 (developer)
2015-04-13 13:20

Done :)
(0039766)
Robert Maynard (manager)
2015-11-02 09:13

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2015-04-13 03:07 nickdesaulniers New Issue
2015-04-13 03:15 Nils Gladitz Relationship added related to 0010692
2015-04-13 04:08 Nils Gladitz Note Added: 0038488
2015-04-13 12:55 nickdesaulniers Note Added: 0038495
2015-04-13 13:03 Nils Gladitz Note Added: 0038497
2015-04-13 13:18 nickdesaulniers Note Added: 0038500
2015-04-13 13:20 Nils Gladitz Note Added: 0038501
2015-04-13 13:20 Nils Gladitz Status new => resolved
2015-04-13 13:20 Nils Gladitz Resolution open => no change required
2015-04-13 13:20 Nils Gladitz Assigned To => Nils Gladitz
2015-11-02 09:13 Robert Maynard Note Added: 0039766
2015-11-02 09:13 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team