CCF: samples/apps/logging cmake undefined pthread

Describe the bug I tried to use cmake to build the sample application (CCF/samples/apps/logging). However, when I run cmake, it pops error about the undefined reference to pthread. Not sure whether the way I run the cmake is correct or incorrect. Thanks.

root@bc8570b00f15:/home/ccf-example-app/CCF/samples/apps/logging# mkdir build
root@bc8570b00f15:/home/ccf-example-app/CCF/samples/apps/logging# cd build
root@bc8570b00f15:/home/ccf-example-app/CCF/samples/apps/logging/build# cmake ..
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- 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  
-- Looking for crypto library - found
-- Looking for dl library - found
-- Performing Test OE_SPECTRE_MITIGATION_C_FLAGS_SUPPORTED
-- Performing Test OE_SPECTRE_MITIGATION_C_FLAGS_SUPPORTED - Failed
-- Performing Test OE_SPECTRE_MITIGATION_CXX_FLAGS_SUPPORTED
-- Performing Test OE_SPECTRE_MITIGATION_CXX_FLAGS_SUPPORTED - Failed
CMake Error at /opt/ccf/cmake/lvi/lvi_mitigation_config.cmake:14 (message):
  LVI mitigation tools must be installed at /opt/oe_lvi
Call Stack (most recent call first):
  /opt/ccf/cmake/ccf_app.cmake:80 (include)
  /opt/ccf/cmake/ccf-config.cmake:31 (include)
  CMakeLists.txt:11 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeOutput.log".
See also "/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeError.log".
root@bc8570b00f15:/home/ccf-example-app/CCF/samples/apps/logging/build# cat /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeError.log
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_8ace1/fast && /usr/bin/make -f CMakeFiles/cmTC_8ace1.dir/build.make CMakeFiles/cmTC_8ace1.dir/build
make[1]: Entering directory '/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8ace1.dir/src.c.o
/usr/bin/cc   -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_8ace1.dir/src.c.o   -c /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_8ace1
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8ace1.dir/link.txt --verbose=1
/usr/bin/cc  -DCMAKE_HAVE_LIBC_PTHREAD    CMakeFiles/cmTC_8ace1.dir/src.c.o  -o cmTC_8ace1 
/usr/bin/ld: CMakeFiles/cmTC_8ace1.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_8ace1.dir/build.make:87: cmTC_8ace1] Error 1
make[1]: Leaving directory '/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_8ace1/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/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp

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



Performing C SOURCE FILE Test OE_SPECTRE_MITIGATION_C_FLAGS_SUPPORTED failed with the following output:
Change Dir: /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_07056/fast && /usr/bin/make -f CMakeFiles/cmTC_07056.dir/build.make CMakeFiles/cmTC_07056.dir/build
make[1]: Entering directory '/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_07056.dir/src.c.o
/usr/bin/cc   -DOE_SPECTRE_MITIGATION_C_FLAGS_SUPPORTED   -mllvm -x86-speculative-load-hardening -o CMakeFiles/cmTC_07056.dir/src.c.o   -c /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp/src.c
cc: error: unrecognized command line option '-mllvm'
make[1]: *** [CMakeFiles/cmTC_07056.dir/build.make:66: CMakeFiles/cmTC_07056.dir/src.c.o] Error 1
make[1]: Leaving directory '/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_07056/fast] Error 2


Source file was:
int main(void) { return 0; }
Performing C++ SOURCE FILE Test OE_SPECTRE_MITIGATION_CXX_FLAGS_SUPPORTED failed with the following output:
Change Dir: /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_558b1/fast && /usr/bin/make -f CMakeFiles/cmTC_558b1.dir/build.make CMakeFiles/cmTC_558b1.dir/build
make[1]: Entering directory '/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_558b1.dir/src.cxx.o
/usr/bin/c++    -pthread -DOE_SPECTRE_MITIGATION_CXX_FLAGS_SUPPORTED   -mllvm -x86-speculative-load-hardening -std=gnu++17 -o CMakeFiles/cmTC_558b1.dir/src.cxx.o -c /home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp/src.cxx
c++: error: unrecognized command line option '-mllvm'
make[1]: *** [CMakeFiles/cmTC_558b1.dir/build.make:66: CMakeFiles/cmTC_558b1.dir/src.cxx.o] Error 1
make[1]: Leaving directory '/home/ccf-example-app/CCF/samples/apps/logging/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_558b1/fast] Error 2


Source file was:
int main() { return 0; }

To Reproduce git clone https://github.com/microsoft/CCF.git cd CCF/samples/apps/logging/ mkdir build cd build cmake …

Expected behavior Makefile shall be generated without error. run “Make” will generate the executable file

Environment information Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

For posterity, I’ve confirmed that the following both work to build the sample app within a Docker container:

Building the sample app at version 1.0.17
$ sudo docker run -it ccfciteam/ccf-app-ci:1.0.17

root@542a97f5b54a:/# cd ~
root@542a97f5b54a:~# git clone https://github.com/microsoft/CCF
Cloning into 'CCF'...
 ...
root@542a97f5b54a:~/CCF# git checkout ccf-1.0.17
Note: switching to 'ccf-1.0.17'.
 ...
root@542a97f5b54a:~/CCF/build# cd ../samples/apps/logging/
root@542a97f5b54a:~/CCF/samples/apps/logging# mkdir build
root@542a97f5b54a:~/CCF/samples/apps/logging# cd build

root@542a97f5b54a:~/CCF/samples/apps/logging/build# CC=$(command -v clang-8) CXX=$(command -v clang++-8) cmake .. -DLVI_MITIGATIONS=OFF
-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
 ...
-- Build files have been written to: /root/CCF/samples/apps/logging/build

root@542a97f5b54a:~/CCF/samples/apps/logging/build# make
Scanning dependencies of target logging.enclave
[ 11%] Building CXX object CMakeFiles/logging.enclave.dir/logging.cpp.o
 ...
[100%] Built target logging
Building the sample app at version 2.0.0-dev7
$ sudo docker run -it ccfciteam/ccf-app-ci:2.0.0-dev7

root@a7caa0dbf346:/# cd ~
root@a7caa0dbf346:~# git clone --branch ccf-2.0.0-dev7 https://github.com/microsoft/CCF.git
Cloning into 'CCF'...
 ...
Note: switching to '89c551e3dbb83b93003f958fb636e726c3d58e8e'.
 ...
root@a7caa0dbf346:~# cd CCF/samples/apps/logging/
root@a7caa0dbf346:~/CCF/samples/apps/logging# mkdir build
root@a7caa0dbf346:~/CCF/samples/apps/logging# cd build/

root@a7caa0dbf346:~/CCF/samples/apps/logging/build# CC=$(command -v clang-10) CXX=$(command -v clang++-10) cmake ..
-- The C compiler identification is Clang 10.0.0
-- The CXX compiler identification is Clang 10.0.0
 ...
-- Build files have been written to: /root/CCF/samples/apps/logging/build

root@a7caa0dbf346:~/CCF/samples/apps/logging/build# make
Scanning dependencies of target logging.enclave
[ 11%] Building CXX object CMakeFiles/logging.enclave.dir/logging.cpp.o
 ...
[100%] Built target logging

A few things to note:

  • Need to explicitly check out the CCF repo at the correct version, or build the Docker image from main if you want to test the latest version of the sample app
  • The 1.x releases are using clang-8, whereas 2.x/main have updated to clang-10. So the guidance in this thread has mixed messages, make sure you’re installing the packages for the correct LLVM version, or rely on the playbooks/Docker image
  • The -DLVI_MITIGATIONS=OFF option I passed in those examples appears to be unnecessary, as the LVI toolchain (for the appropriate clang version) is included in the app-ci image
  • Installing libc++-10-dev will uninstall CCF, if you have a 1.x release installed at /opt/ccf