title: Cmake cannot find pthread and pthreads
body: <p>I am trying to install the following application on Ubuntu 20.04 LTS:
  <a href="https://villas.fein-aachen.org/doc/node-installation.html" rel="nofollow noreferrer">https://villas.fein-aachen.org/doc/node-installation.html</a>.</p>
  <p>All the required packages seem installed and updated at the most recent version.
  Unfortunately, when I run <code>cmake ..</code> it returns me the following errors:</p>
  <pre><code>```-- The C compiler identification is GNU 9.3.0 
     -- The CXX compiler identification is GNU 9.3.0
     -- Detecting C compiler ABI info
     -- Detecting C compiler ABI info - done
     -- Check for working C compiler: /usr/bin/cc - skipped
     -- Detecting C compile features
     -- Detecting C compile features - done
     -- Detecting CXX compiler ABI info
     -- Detecting CXX compiler ABI info - done
     -- Check for working CXX compiler: /usr/bin/c++ - skipped
     -- Detecting CXX compile features
     -- Detecting CXX compile features - done
     -- 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 thread
     -- Looking for pthread_create in pthread - found
     -- Found Threads: TRUE  
     -- Found PkgConfig: /usr/bin/pkg-config (found version &quot;0.29.1&quot;) 
     -- Looking for sys/eventfd.h
     -- Looking for sys/eventfd.h - found
     -- Looking for semaphore.h
     -- Looking for semaphore.h - found
     -- Looking for sys/mman.h
     -- Looking for sys/mman.h - found
     -- Found OpenMP_C: -fopenmp (found version &quot;4.5&quot;) 
     -- Found OpenMP_CXX: -fopenmp (found version &quot;4.5&quot;) 
     -- Found OpenMP: TRUE (found version &quot;4.5&quot;)  
     -- Could NOT find Opal (missing: OPAL_LIBRARY OPAL_LIBRARY_UTILS OPAL_LIBRARY_CORE OPAL_LIBRARY_IRC OPAL_INCLUDE_DIR) 
    -- Found IBVerbs: /usr/lib/x86_64-linux-gnu/libibverbs.so  
    -- Found RDMACM: /usr/lib/x86_64-linux-gnu/librdmacm.so  
    -- Found Etherlab: /usr/local/lib/libethercat.so  
    -- Found Lua: /usr/lib/x86_64-linux-gnu/liblua5.3.so;/usr/lib/x86_64-linux-gnu/libm.so (found version &quot;5.3.3&quot;) 
    -- Checking for module 'jansson&gt;=2.9'
    -- Found jansson, version 2.12
    -- Checking for module 'libwebsockets&gt;=2.3.0'
    -- Found libwebsockets, version 4.0.22
    -- Checking for module 'protobuf&gt;=2.6.0'
    -- Found protobuf, version 3.6.1
    -- Checking for module 'libprotobuf-c&gt;=1.1.0'
    -- Found libprotobuf-c, version 1.3.3
    -- Checking for module 'criterion&gt;=2.3.1'
    -- Found criterion, version 2.3.3
    -- Checking for module 'libnl-route-3.0&gt;=3.2.27'
    -- Found libnl-route-3.0, version 3.4.0
    -- Checking for module 'libiec61850&gt;=1.3.1'
    -- Found libiec61850, version 1.4.3
    -- Checking for module 'libconfig&gt;=1.4.9'
    -- Found libconfig, version 1.5
    -- Checking for module 'libmosquitto&gt;=1.6.9'
    -- Found libmosquitto, version 1.6.9
    -- Checking for module 'rdkafka&gt;=1.5.0'
    -- Found rdkafka, version 1.6.0
    -- Checking for module 'hiredis&gt;=1.0.0'
    -- Found hiredis, version 1.0.0
    -- Checking for module 'redis++&gt;=1.2.0'
    -- Found redis++, version 1.2.3
    -- Checking for module 'librabbitmq&gt;=0.8.0'
    -- Found librabbitmq, version 0.10.0
    -- Checking for module 'comedilib&gt;=0.11.0'
    -- Found comedilib, version 0.11.0
    -- Checking for module 'libzmq&gt;=2.2.0'
    -- Found libzmq, version 4.3.2
    -- Checking for module 'libuldaq&gt;=1.0.0'
    -- Found libuldaq, version 1.2.0
    -- Checking for module 'uuid&gt;=2.23'
    -- Found uuid, version 2.34.0
    -- Checking for module 'libcgraph&gt;=2.30'
    -- Found libcgraph, version 2.49.0
    -- Checking for module 'libgvc&gt;=2.30'
    -- Found libgvc, version 2.49.0
    -- Checking for module 'libusb-1.0&gt;=1.0.23'
    -- Found libusb-1.0, version 1.0.23
    -- Checking for module 'libxil'
    -- Found libxil, version 1.0.0
    -- Checking for module 'nanomsg'
    -- Found nanomsg, version 1.1.5
    -- Checking for module 're&gt;=0.5.6'
    -- No package 're' found
    -- Checking for module 'libre&gt;=0.5.6'
    -- Found libre, version 0.6.0
    -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found suitable version &quot;1.1.1f&quot;, minimum required is &quot;1.0.0&quot;)  
    -- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found suitable version &quot;7.68.0&quot;, minimum required is &quot;7.29&quot;)  
    -- Could NOT find Criterion (missing: CRITERION_LIBRARY) 
    -- Checking for module 'jansson&gt;=2.7'
    -- Found jansson, version 2.12
    CMake Error at CMakeLists.txt:225 (add_subdirectory):
    The source directory
  
     /home/lab/VILLASnode/fpga
  
     does not contain a CMakeLists.txt file.
     ```
  </code></pre>
  <p>Unfortunately, after this I cannot complete with my installation. The log file returns me:</p>
  <pre><code>Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
  Change Dir: /home/lab/VILLASnode/build/CMakeFiles/CMakeTmp
  
  Run Build Command(s):/usr/bin/make cmTC_e442c/fast &amp;&amp; /usr/bin/make -f CMakeFiles/cmTC_e442c.dir/build.make CMakeFiles/cmTC_e442c.dir/build
  make[1]: Entering directory '/home/lab/VILLASnode/build/CMakeFiles/CMakeTmp'
  Building C object CMakeFiles/cmTC_e442c.dir/src.c.o
  /usr/bin/cc   -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_e442c.dir/src.c.o   -c /home/lab/VILLASnode/build/CMakeFiles/CMakeTmp/src.c
  Linking C executable cmTC_e442c
  /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e442c.dir/link.txt --verbose=1
  /usr/bin/cc  -DCMAKE_HAVE_LIBC_PTHREAD    CMakeFiles/cmTC_e442c.dir/src.c.o  -o cmTC_e442c 
  /usr/bin/ld: CMakeFiles/cmTC_e442c.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_e442c.dir/build.make:87: cmTC_e442c] Error 1
  make[1]: Leaving directory '/home/lab/VILLASnode/build/CMakeFiles/CMakeTmp'
  make: *** [Makefile:121: cmTC_e442c/fast] Error 2
  
  
  Source file was:
  #include &lt;pthread.h&gt;
  
  void* test_func(void* data)
  {
    return data;
  }
  
  int main(void)
  {
    pthread_t thread;
    pthread_create(&amp;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/lab/VILLASnode/build/CMakeFiles/CMakeTmp
  
  Run Build Command(s):/usr/bin/make cmTC_4179b/fast &amp;&amp; /usr/bin/make -f CMakeFiles/cmTC_4179b.dir/build.make CMakeFiles/cmTC_4179b.dir/build
  make[1]: Entering directory '/home/lab/VILLASnode/build/CMakeFiles/CMakeTmp'
  Building C object CMakeFiles/cmTC_4179b.dir/CheckFunctionExists.c.o
  /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_4179b.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
  Linking C executable cmTC_4179b
  /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4179b.dir/link.txt --verbose=1
  /usr/bin/cc  -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_4179b.dir/CheckFunctionExists.c.o  -o cmTC_4179b  -lpthreads 
  /usr/bin/ld: cannot find -lpthreads
  collect2: error: ld returned 1 exit status
  make[1]: *** [CMakeFiles/cmTC_4179b.dir/build.make:87: cmTC_4179b] Error 1
  make[1]: Leaving directory '/home/lab/VILLASnode/build/CMakeFiles/CMakeTmp'
  make: *** [Makefile:121: cmTC_4179b/fast] Error 2
  </code></pre>
  <p>How can I solve this issue? (pthread and libc6 are correctly installed)</p>
  <p>Thank you in advance for any suggestion!</p>