MantisBT - CMake
View Issue Details
0010710CMakeModulespublic2010-05-13 19:112016-06-10 14:31
Daniel Richard G. 
Bill Hoffman 
normalmajoralways
closedmoved 
CMake-2-8 
 
0010710: FindThreads.cmake does not work properly on Tru64
find_package(Threads) in CMake 2.8.1 does not work correctly on OSF/Tru64. There are multiple problems with the module as it is currently written:

1. At line 141, there is a platform-specific conditional (CMAKE_SYSTEM MATCHES "OSF1-V*") that blanks out the name of the pthread library. This is not correct for my particular system; without a threading directive passed to the compiler, code fails to link due to missing pthread functions.

2. Prior to that point, the module does find -lpthread. But this is not the correct directive to use, according to the cc(1) man page: it's -pthread. (Note, of course, that this does not necessarily apply if GCC is being used.)

3a. The situation on this system is even more complicated than that, however. Both -lpthread (singular) and -lpthreads (plural) exist, and

3b. -lpthreads exports "pthread_create", while -lpthread exports "__pthread_create", and

3c. If you do a normal CHECK_LIBRARY_EXISTS() call, then -lpthreads appears to be the correct library. But if you do your own test program, which #includes pthread.h, pthread_create() becomes a preprocessor macro that expands to __pthread_create(). So -lpthread is the actual library needed.


Here's what I see as the takeaway:

1. If -pthread/-thread/-mt/etc. does the trick, use that in preference to any -l* library specifier.

2. The function-link test has to be done with a source file that #includes pthread.h, otherwise it's useless.

3. There's no need to special-case OSF/Tru64, because a robust enough FindThreads module can handle it.
No tags attached.
Issue History
2010-05-13 19:11Daniel Richard G.New Issue
2010-08-03 12:24Kovarththanan RajaratnamCategoryCMake => Modules
2010-12-15 09:11David ColeAssigned To => Bill Hoffman
2010-12-15 09:11David ColeStatusnew => assigned
2014-10-06 16:20Rolf Eike BeerNote Added: 0036988
2016-06-10 14:28Kitware RobotNote Added: 0041696
2016-06-10 14:28Kitware RobotStatusassigned => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0036988)
Rolf Eike Beer   
2014-10-06 16:20   
Does using "-pthread" in both CMAKE_C_FLAGS and target_link_libraries() at the same time work? In this case this would be just another instance of "-pthread should be preferred over explicitely specifying a library". Does this problem still exist in 3.0.2 or newer at all?
(0041696)
Kitware Robot   
2016-06-10 14:28   
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.