Compiling error /usr/bin/ld: cannot find -lpthreads

Hi

New to forum. I think that I am in the right place?

Ubuntu 20.04.

I am trying to compile from source using the instructions from BUILDING.md and I am getting this error message:

/usr/bin/ld: cannot find -lpthreads

The error log:

===
Checking whether the ASM_NASM compiler is GNU using “–version” did not match “(GNU assembler)|(GCC)|(Free Software Foundation)”:
Checking whether the ASM_NASM compiler is Clang using “–version” did not match “(clang version)”:
Checking whether the ASM_NASM compiler is AppleClang using “–version” did not match “(Apple LLVM version)”:
Checking whether the ASM_NASM compiler is ARMClang using “–version” did not match “armclang”:
Checking whether the ASM_NASM compiler is HP using “-V” did not match “HP C”:
Checking whether the ASM_NASM compiler is Intel using “–version” did not match “(ICC)”:
Checking whether the ASM_NASM compiler is SunPro using “-V” did not match “Sun C”:
Checking whether the ASM_NASM compiler is XL using “-qversion” did not match “XL C”:
Checking whether the ASM_NASM compiler is MSVC using “-?” did not match “Microsoft”:
Checking whether the ASM_NASM compiler is TI using “-h” did not match “Texas Instruments”:
Checking whether the ASM_NASM compiler is IAR using “” did not match “IAR Assembler”:
Checking whether the ASM_NASM compiler is ARMCC using “” did not match “(ARM Compiler)|(ARM Assembler)”:
Checking whether the ASM_NASM compiler is NASM using “-v” did not match “(NASM version)”:
Checking whether the ASM_NASM compiler is YASM using “–version” did not match “(yasm)”:
Checking whether the ASM_NASM compiler is ADSP using “-version” did not match “Analog Devices”:
Checking whether the ASM_NASM compiler is QCC using “-V” did not match “gcc_nto”:
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_b2fd3/fast && /usr/bin/make -f CMakeFiles/cmTC_b2fd3.dir/build.make CMakeFiles/cmTC_b2fd3.dir/build
make[1]: Entering directory ‘/home/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp’
Building C object CMakeFiles/cmTC_b2fd3.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_b2fd3.dir/src.c.o -c /home/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_b2fd3
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b2fd3.dir/link.txt --verbose=1
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD CMakeFiles/cmTC_b2fd3.dir/src.c.o -o cmTC_b2fd3 -lstdc++fs -lm -latomic -ldl
/usr/bin/ld: CMakeFiles/cmTC_b2fd3.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_b2fd3.dir/build.make:87: cmTC_b2fd3] Error 1
make[1]: Leaving directory ‘/home/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp’
make: *** [Makefile:121: cmTC_b2fd3/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/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_4865c/fast && /usr/bin/make -f CMakeFiles/cmTC_4865c.dir/build.make CMakeFiles/cmTC_4865c.dir/build
make[1]: Entering directory ‘/home/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp’
Building C object CMakeFiles/cmTC_4865c.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_4865c.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_4865c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4865c.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_4865c.dir/CheckFunctionExists.c.o -o cmTC_4865c -lpthreads -lstdc++fs -lm -latomic -ldl
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_4865c.dir/build.make:87: cmTC_4865c] Error 1
make[1]: Leaving directory ‘/home/username/Downloads/Audacity/audacity-build/CMakeFiles/CMakeTmp’
make: *** [Makefile:121: cmTC_4865c/fast] Error 2

I think that I have followed the instructions properly and my Internet search is not getting me any answers.

I would appreciate any hints to resolve this.

Thanks

I fixed the problem.

The version of cmake for Ubuntu 20.04 was old and did not work.

I had to install cmake manually to the latest version. From there, it was O.K.