1

I am trying to build webrtc project: https://github.com/mpromonet/webrtc-streamer?fbclid=IwAR2HBwWIZvRhSlmKBllQj2knaBPn6oeEvS24STPLTZHbky2Ta5sbcoPCoc8

when I run cmake . I got the following error:

WEBRTCBUILD = Release
WEBRTCROOT = /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/../webrtc
WEBRTCDESKTOPCAPTURE= ON
CMAKE_CXX_COMPILER_ID=GNU
ALSA_FOUND = FALSE
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
WEBRTC_LIBRARY
    linked by target "webrtc-streamer" in directory /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer

-- Configuring incomplete, errors occurred!
See also "/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeOutput.log".
See also "/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeError.log".

And hereafter the content of "CMakeError.log"

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_13271/fast"
/usr/bin/make -f CMakeFiles/cmTC_13271.dir/build.make CMakeFiles/cmTC_13271.dir/build
make[1]: Entering directory '/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o
/usr/bin/cc    -fPIE   -o CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o   -c /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_13271
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_13271.dir/link.txt --verbose=1
/usr/bin/cc       CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o  -o cmTC_13271 -rdynamic 
CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_13271.dir/build.make:97: recipe for target 'cmTC_13271' failed
make[1]: *** [cmTC_13271] Error 1
make[1]: Leaving directory '/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_13271/fast' failed
make: *** [cmTC_13271/fast] Error 2

   
File /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Here after the CMakeLists.txt: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt

the pthread library is installed on my ubuntu PC because compiling a test file "test.c" with -lpthread is working without problem

What I am missing ?

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
  • 1
    Does this answer your question? [Undefined reference to pthread\_create in Linux](https://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux) – Marek R Jul 20 '20 at 09:44
  • 1
    From the suggested duplicate, especially this answer might be relevant: https://stackoverflow.com/a/57685932/6782754 – Gerhardh Jul 20 '20 at 09:45
  • @MarekR this is not about linking issue to pthread. This question is about cmake issue. I can compile a test file (.c) with -lpthread without any problem – MOHAMED Jul 20 '20 at 10:01
  • @MOHAMED Your error IS linking issue. Second comment points directly to answer (in duplicate I've provided) how to fix it in cmake project. – Marek R Jul 20 '20 at 11:08
  • @MarekR I tried the proposal in the link duplicate but it does not fix the issue – MOHAMED Jul 20 '20 at 11:46
  • What version of CMake are you using? – Kevin Jul 20 '20 at 12:52
  • 1
    The error is about not finding `webrtc` library, which should be a value of `WEBRTC_LIBRARY` variable. Content of `CMakeError.log` is absolutely **unrelated to the problem**, and you may safely remove it from the post. Specifically, that line fails: [find_library(WEBRTC_LIBRARY NAMES webrtc PATHS ${WEBRTCOBJS})](https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt#L122). As described in the [README](https://github.com/mpromonet/webrtc-streamer/blob/master/README.md#build-webrtc-streamer), WebRTC SDK is expected to be located under `../webrtc` directory. Make sure you have it – Tsyvarev Jul 20 '20 at 12:57

1 Answers1

1

You need to have 'pthread' added into 'target_link_libraries' section in your CMakeLists.txt.

[edit]

As suggested by @arrowd, the proper way is to use the 'FindThreads': https://cmake.org/cmake/help/latest/module/FindThreads.html

b00rt00s
  • 114
  • 5