2022-06-27

slitaz-41 -- slim-cmake-lpthreads


slitaz-41 -- slim-cmake-lpthreads 

Building error using cmake: cannot find -lpthreads

Hint: search for the actual error message

The one for "-lpthreads" just accidentally happened to be the last one in the log...


Solution: go through the log from the top, identify the section with the configure checks, find the last configure check prior to the point, where CMake identifies failure and dumps its logs. You might also try so search for the text "Configuring incomplete, errors occurred!"



I fight with slim :/.

Issue with cmake build :

-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for one of the modules 'fontconfig'
CMake Error at /usr/share/cmake-3.22/Modules/FindPkgConfig.cmake:890 (message):
None of the required 'fontconfig' found
Call Stack (most recent call first):
cmake/modules/FONTCONFIGConfig.cmake:18 (pkg_search_module)
CMakeLists.txt:108 (find_package)

FontConfig Found
PAM disabled
ConsoleKit disabled
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- 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
-- Found Threads: TRUE
-- Configuring incomplete, errors occurred!

Run Build Command(s):/usr/bin/make -f Makefile cmTC_88b6c/fast && /usr/bin/make -f CMakeFiles/cmTC_88b6c.dir/build.make CMakeFiles/cmTC_88b6c.dir/build
make[1]: Entering directory '/home/slitaz/wok/slim/source/slim-1.3.6/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_88b6c.dir/CheckFunctionExists.c.o
/usr/bin/cc -march=i486 -Os -pipe -fomit-frame-pointer -Wall -g -O2 -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_88b6c.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.22/Modules/CheckFun
Linking C executable cmTC_88b6c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_88b6c.dir/link.txt --verbose=1
/usr/bin/cc -march=i486 -Os -pipe -fomit-frame-pointer -Wall -g -O2 -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_88b6c.dir/CheckFunctionExists.c.o -o cmTC_88b6c -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_88b6c.dir/build.make:99: cmTC_88b6c] Error 1
make[1]: Leaving directory '/home/slitaz/wok/slim/source/slim-1.3.6/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:127: cmTC_88b6c/fast] Error 2


https://forum.slitaz.org/topic/slitaz-development-strategy-direction/page/5#post-50768 


Asked 
Viewed 112k times
45

I have c++ project that was smoothly running on a given machine, and now I am trying to compile it on another one with the same operating system (Xubuntu 14.04).

I've installed all the dependencies and I'am using cmake to build the project, although it stops with the following error:

Determining if the function pthread_create exists in the pthreads failed with the following output: ... /usr/bin/ld: cannot find -lpthreads



 


 


 

9 Answers

31

The problem was happening when running cmake. Though, in this case cmake was not the problem the error was silent and the -lpthreads related error/warning was the only thing being written to the cmake error log file, although that was not causing any issue. I've done a minimal version of the cmakelists.txt and started testing it line by line until I found which package was causing it to stop: finally I found it was a version mismatch...

Hint: search for the actual error message

Typically you'd look for the last error message. However, this (often useful) strategy in such cases leads astray.

What you are looking at is the CMakeCache.txt, the CMakeOutput.log or the CMakeError.logHow comes? When some of the macros or tests in the configure phase fails, CMake "helpfully" dumps these files to the output. Unfortunately, these files can be thousands of lines long, and typically contain lots of "*** Error: xyz" entries, for various configure checks. The one for "-lpthreads" just accidentally happened to be the last one in the log...

Solution: go through the log from the top, identify the section with the configure checks, find the last configure check prior to the point, where CMake identifies failure and dumps its logs. You might also try so search for the text "Configuring incomplete, errors occurred!"

Typically you'll either find a very precise actual error message there, or at least you find the name / path of the macro or function called last, and this allows you to pinpoint down what actually went wrong.