PDA

View Full Version : CMake and pthreads



Matt Smith
3rd September 2006, 20:35
Hi everyone,

Does anyone know how to get CMake to configure properly without looking for a non-existent "pthreads" library? I'm using Qt 4.1.4 in packages on Fedora Core 5. My output reads as follows:


-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: c++
-- Check for working CXX compiler: c++ -- works
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - found
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found.
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - not found.
-- Found Qt-Version 4.1.4
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
CMake Error: Attempt to add link library "-lpthread" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "dl" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libQtGui.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "-lSM" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "-lICE" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libX11.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libXext.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libQtNetwork.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libQtNetwork_debug.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libQtXml.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
CMake Error: Attempt to add link library "/usr/lib/libQtXml_debug.so" to target "/usr/lib/libQtCore.so" which is not built by this project.
-- Configuring done

And the relevant section in CMakeFiles/CMakeError.log reads as follows:


Determining if the function pthread_create exists in the pthreads failed with the follow
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec.dir/build.make CMakeFiles/cmTryCompileExec
gmake[1]: Entering directory `/home/indigojo/cvs/0.3/catkin-qtm/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/indigojo/cvs/0.3/catkin-qtm/CMakeFiles/CMa
Building C object CMakeFiles/cmTryCompileExec.dir/usr/share/cmake/Modules/CheckFunctionE
/usr/bin/gcc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTryCompileExec.di
Linking C executable cmTryCompileExec
/usr/bin/cmake -P CMakeFiles/cmTryCompileExec.dir/cmake_clean_target.cmake
/usr/bin/gcc -DCHECK_FUNCTION_EXISTS=pthread_create -fPIC "CMakeFiles/cmTryCompile
/usr/bin/ld: cannot find -lpthreads
collect2: ld returned 1 exit status
gmake[1]: *** [cmTryCompileExec] Error 1
gmake[1]: Leaving directory `/home/indigojo/cvs/0.3/catkin-qtm/CMakeFiles/CMakeTmp'
gmake: *** [cmTryCompileExec/fast] Error 2

This is the first time I've actually written a CMakeLists.txt file and tried to run it, so I'm really quite new to the game, but I wanted to build an installable source bundle for my application. Is the solution to this to suppress the attempt to use the non-existent pthreads library, and if so how? If not, does anyone know what one does?

wysota
3rd September 2006, 20:41
AFAIK Qt requires pthreads, so it won't be possible to proceed without it.

Matt Smith
3rd September 2006, 20:46
AFAIK Qt requires pthreads, so it won't be possible to proceed without it.

I've been using QMake since the start, and the resulting binary has used -lpthread (no s on the end) and works fine.

jacek
3rd September 2006, 20:57
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread - found
There's nothing wrong here. It didn't find the function it was looking for in libpthreads, so it used libpthread instead.


CMake Error: Attempt to add link library "-lpthread" to target "/usr/lib/libQtCore.so" which is not built by this project.
How does your TARGET_LINK_LIBRARIES line look like?

Matt Smith
3rd September 2006, 21:32
There's nothing wrong here. It didn't find the function it was looking for in libpthreads, so it used libpthread instead.


How does your TARGET_LINK_LIBRARIES line look like?

Like this:


TARGET_LINK_LIBRARIES(
${QT_LIBRARIES}
${QT_QTNETWORK_LIBRARIES}
${QT_QTXML_LIBRARIES}
)

jacek
3rd September 2006, 21:42
It should be:
TARGET_LINK_LIBRARIES( program_name ${QT_LIBRARIES} )
and add

SET( QT_USE_QTNETWORK TRUE )
SET( QT_USE_QTXML TRUE ) before FIND_PACKAGE().

http://wiki.qtcentre.org/index.php?title=Compiling_Qt4_apps_with_CMake