MantisBT - CMake
View Issue Details
0010692CMakeModulespublic2010-05-09 11:352016-06-10 14:31
Modestas Vainius 
Philip Lowman 
normalminoralways
closedmoved 
amd64Debian GNU/Linuxsid
CMake-2-8 
 
0010692: FindBoost fails to add -lpthread
When using
   find_package(Boost COMPONENTS thread REQUIRED)
-lpthread is not added to the link command, causing the link to fail if
binutils-gold (which has --no-add-needed behavior as default) is used.

More informations can be found at
 http://wiki.debian.org/qa.debian.org/FTBFS#A2009-11-02Packagesfailingbecausebinutils-gold.2BAC8-indirectlinking [^]
Small testcase is attached to Debian bug report.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=563479 [^]

I tried to fix the bug myself but apparently FindBoost.cmake is not every easy to grasp :/
No tags attached.
has duplicate 0011238closed  FindBoost.cmake should add thread library to Boost_LIBRARIES 
related to 0014720closed  FindBoost handles pthread different on first and second run 
related to 0015510closed Nils Gladitz After 15.04 upgrade, cannot link against against pthread using C++11 <thread> 
diff FindBoost_add_-lpthread_#563479.diff (898) 2011-01-16 12:34
https://public.kitware.com/Bug/file/3629/FindBoost_add_-lpthread_%23563479.diff
? FindBoost.cmake (52,930) 2011-06-10 01:06
https://public.kitware.com/Bug/file/3928/FindBoost.cmake
diff FindBoost+add_pthread_if_boost_threads_is_in_use.diff (2,099) 2011-06-10 01:06
https://public.kitware.com/Bug/file/3929/FindBoost%2Badd_pthread_if_boost_threads_is_in_use.diff
? BoostPthreadWorkaround.cmake (783) 2012-08-02 17:15
https://public.kitware.com/Bug/file/4414/BoostPthreadWorkaround.cmake
diff FindBoost+add_pthread_if_boost_threads_is_in_use_2.8.11-rc1.diff (1,669) 2013-03-16 14:58
https://public.kitware.com/Bug/file/4683/FindBoost%2Badd_pthread_if_boost_threads_is_in_use_2.8.11-rc1.diff
Issue History
2010-05-09 11:35Modestas VainiusNew Issue
2010-09-10 23:48Philip LowmanStatusnew => assigned
2010-09-10 23:48Philip LowmanAssigned To => Philip Lowman
2010-09-15 15:01Philip LowmanNote Added: 0022230
2010-09-15 15:02Philip LowmanRelationship addedhas duplicate 0011238
2011-01-16 12:34CuranFile Added: FindBoost_add_-lpthread_#563479.diff
2011-01-16 12:41CuranNote Added: 0024730
2011-06-10 01:06Philip LowmanNote Added: 0026815
2011-06-10 01:06Philip LowmanFile Added: FindBoost.cmake
2011-06-10 01:06Philip LowmanFile Added: FindBoost+add_pthread_if_boost_threads_is_in_use.diff
2012-08-02 17:14Michael TänzerNote Added: 0030159
2012-08-02 17:15Michael TänzerFile Added: BoostPthreadWorkaround.cmake
2013-03-16 14:58Modestas VainiusFile Added: FindBoost+add_pthread_if_boost_threads_is_in_use_2.8.11-rc1.diff
2013-03-16 14:58Modestas VainiusNote Added: 0032648
2014-01-27 10:46Nils GladitzRelationship addedrelated to 0014720
2015-04-13 03:15Nils GladitzRelationship addedrelated to 0015510
2016-06-10 14:27Kitware RobotNote Added: 0041693
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0022230)
Philip Lowman   
2010-09-15 15:01   
See also
http://public.kitware.com/Bug/view.php?id=11121, [^] http://www.cmake.org/pipermail/cmake/2010-September/039510.html [^]
(0024730)
Curan   
2011-01-16 12:41   
I've created a patch for Debian, the current version is now attached to this bug report, the latest version can be found at [0]. Testing shows it working, though I'm not sure you want to take this verbatim, while it is ok for Debian until there is a upstream sanctioned solution, it might not be fit for direct inclusion.

As a side note: maybe the whole file (FindBoost.cmake) can be drastically simplified if Boost includes that auto-generated pkg-config file from [1].

[0] http://git.debian.org/?p=collab-maint/cmake.git;a=blob;f=debian/patches/FindBoost_add_-lpthread_%23563479.diff;hb=HEAD [^]
[1] https://svn.boost.org/trac/boost/ticket/1094 [^]
(0026815)
Philip Lowman   
2011-06-10 01:06   
The patch for Debian will not survive after the initial configure (due to how FindBoost is written). Also it causes pthread to be added on Cygwin where Windows threads is being used.

I've attached a (beta) FindBoost here for additional testing by others (and also a patch).
(0030159)
Michael Tänzer   
2012-08-02 17:14   
I guess I have a system with the described debian patch here (Ubuntu 12.04) and can confirm that it is buggy. It only adds pthread on the first CMake run (which is probably enough for automatic package generation but not for anyone else) and also because pthread is only added as library basename not as full path static linking fails.

Looking through the patch provided by Philip Lowman his solution does not seem to have these problems. But I would suggest to rename the BOOST_THREAD_LIBRARY variable because it is easy to be confused with Boost_THREAD_LIBRARY which is set to the path to the libboost_thread.so and to mark it as advanced.

Until this is fixed in CMake I have done a BoostPthreadWorkaround.cmake file which I will attach to this bug.
(0032648)
Modestas Vainius   
2013-03-16 14:58   
Hereby I attach an updated version of FindBoost+add_pthread_if_boost_threads_is_in_use.diff patch which applies and works with cmake 2.8.11-rc1. I intend to ship it with Debian cmake package replacing the old buggy patch.
(0041693)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.