cmake breaks: cannot find -lpthreads

Having issues with the site, hardware, source code, or any other issues?
Post Reply
tybalt
Posts: 2
Joined: Tue Aug 16, 2022 12:49 pm

cmake breaks: cannot find -lpthreads

Post by tybalt »

trying to compile libbladeRF and cmake is running into errors.

I installed the bladeRF software using apt-get

cmake ../
CMake Error at libraries/libbladeRF/CMakeLists.txt:122 (message):
No libbladeRF backends are enabled. Please enable one or more backends.

So I installed cmake-gui and checked "ENABLE_BACKEND_LIBUSB" checkbox.

Configure breaks:
CMakeError.log:
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_b7f45/fast && /usr/bin/make -f CMakeFiles/cmTC_b7f45.dir/build.make CMakeFiles/cmTC_b7f45.dir/build
make[1]: Entering directory '/home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_b7f45.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_b7f45.dir/src.c.o -c /home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_b7f45
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b7f45.dir/link.txt --verbose=1
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -rdynamic CMakeFiles/cmTC_b7f45.dir/src.c.o -o cmTC_b7f45
/usr/bin/ld: CMakeFiles/cmTC_b7f45.dir/src.c.o: in function `main':
src.c:(.text+0x46): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x52): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x63): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_b7f45.dir/build.make:87: cmTC_b7f45] Error 1
make[1]: Leaving directory '/home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_b7f45/fast] Error 2

Source file was:
#include <pthread.h>

void* test_func(void* data)
{
return data;
}

int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);

return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_a2012/fast && /usr/bin/make -f CMakeFiles/cmTC_a2012.dir/build.make CMakeFiles/cmTC_a2012.dir/build
make[1]: Entering directory '/home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_a2012.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_a2012.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_a2012
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a2012.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_a2012.dir/CheckFunctionExists.c.o -o cmTC_a2012 -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_a2012.dir/build.make:87: cmTC_a2012] Error 1
make[1]: Leaving directory '/home/tybalt/wiphy-build/bladeRF/host/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_a2012/fast] Error 2

A similar problem appears to be solved by making an edit to host/libraries/libbladeRF/src/device_identifier.c, but this file is not in my directory. Not sure if I'm going down the right rabbit hole.
robert.ghilduta
Posts: 156
Joined: Thu Feb 28, 2013 11:14 pm

Re: cmake breaks: cannot find -lpthreads

Post by robert.ghilduta »

Is the pthreads library debian package ( libpthread-stubs0-dev ) installed? If not, please try to apt-get install build-essentials along with libpthread-stubs0-dev .
Post Reply