Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cmake无法配置pthread错误_Cmake_Pthreads - Fatal编程技术网

cmake无法配置pthread错误

cmake无法配置pthread错误,cmake,pthreads,Cmake,Pthreads,我正在尝试使用cmake配置项目,但我收到一个错误。CMakeError.log中的内容如下 Change Dir: /home/jjcasmar/D/libs/builds/sofa/CMakeFiles/CMakeTmp Run Build Command(s):/usr/bin/make cmTC_9feda/fast && /usr/bin/make -f CMakeFiles/cmTC_9feda.dir/build.make CMakeFiles/cmTC_9fed

我正在尝试使用cmake配置项目,但我收到一个错误。CMakeError.log中的内容如下

Change Dir: /home/jjcasmar/D/libs/builds/sofa/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_9feda/fast && /usr/bin/make -f CMakeFiles/cmTC_9feda.dir/build.make CMakeFiles/cmTC_9feda.dir/build
make[1]: Entering directory '/mnt/D/jjcasmar/libs/builds/sofa/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_9feda.dir/src.c.o
/usr/bin/cc   -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_9feda.dir/src.c.o   -c /home/jjcasmar/D/libs/builds/sofa/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_9feda
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9feda.dir/link.txt --verbose=1
/usr/bin/cc  -DCMAKE_HAVE_LIBC_PTHREAD    -rdynamic CMakeFiles/cmTC_9feda.dir/src.c.o  -o cmTC_9feda 
/usr/bin/ld: CMakeFiles/cmTC_9feda.dir/src.c.o: in function `main':
src.c:(.text+0x3e): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x4a): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x5b): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_9feda.dir/build.make:87: cmTC_9feda] Error 1
make[1]: Leaving directory '/mnt/D/jjcasmar/libs/builds/sofa/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_9feda/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;
}

我尝试了一个非常简单的CMakeLists(如下所示)来检查pthreads是否正常工作,以及看起来是否正常工作(配置和构建正常)

配置时使用以下输出

-- 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
-- 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
-- Configuring done
-- Generating done

我不知道如何找到问题的原因。任何想法都会有帮助

我可以确认您的样品在我的装有cmake 3.15.5的机器上正常工作。请注意,它说
——执行测试CMAKE\u HAVE\u LIBC\u PTHREAD-失败
,但调用cc时使用
DCMAKE\u HAVE\u LIBC\u PTHREAD
。这样可以吗?而且任何地方都没有
-lpthread
。在本地,我在运行
make VERBOSE=1
/usr/local/bin/c++CMakeFiles/Test.dir/a.cpp.o-o Test-lpthread
。我做的测试工作正常。问题一定出在大项目上,但直到昨天fnie还在运行。不确定从哪里开始查找atI不知道您的项目,所以我不能说,您可能无法在此处显示它,即使您可以,它可能太大,任何人都无法快速找到错误,但对于初学者,您可以删除所有Cmake缓存并再次运行构建。我会调查
-DCMAKE\u HAVE\u LIBC\u PTHREAD
,我觉得它很可疑。你在运行你发布的最简单的示例时也看到了吗?我不确定出了什么问题,我完全重置了源代码(不知为什么它更改了ExternalProjects.cmake文件),这就解决了问题。
cmake_minimum_required(VERSION 3.10)
project(Test)

find_package(Threads REQUIRED)

add_executable(Test a.cpp)
target_link_libraries(Test Threads::Threads)
-- 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
-- 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
-- Configuring done
-- Generating done