cmake 无法配置并出现 pthread 错误

2024-02-26

我正在尝试使用 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;
}

尽管如此,它表示编译器正确接受 -pthread

-- Found PythonInterp: /usr/bin/python (found version "3.8.2")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE

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

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

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


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

cmake 无法配置并出现 pthread 错误 的相关文章

  • 如何在使用 Cmake 构建期间编译 HLSL 着色器?

    我正在开发 d3d 应用程序 我想在使用 cmake 构建期间编译我的 hlsl 着色器 我不知道从哪里开始 这是我当前的 CMakeLists txt cmake minimum required VERSION 3 20 project
  • 为什么 cmake 在 git commit 后编译所有内容

    假设我有时在 Linux 上使用 cmake 2 8 编译一段代码 我更改了一个文件 my changed file 运行 cmake 并且只构建了这个文件 到目前为止 一切都很好 现在我想提交这个 git add my changed f
  • 多线程调试器[关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 GDB 在使用多线程 pthreads 进行调试时存在严重问题 nix 上还有其他好的 C C 多线程调
  • 如何使用cmake查找库?

    要将可执行文件与驻留在标准位置的库链接 可以在 CmakeLists txt 文件中执行以下操作 create executable generate mesh generate mesh cpp target link libraries
  • 使用 CMake 和 clang 在 Windows 上构建简单的 C++ 项目

    我正在尝试在 Windows 10 上构建一个简单的 Hello World 程序 最好使用 CMake 和 clang 如果我使用 MinGW 的 g 编译器 我可以成功编译 链接和运行同一个项目 但当我尝试使用 clang 时会遇到问题
  • CMake 警告:无法为目标生成安全的链接器搜索路径

    在为 pcl 项目运行 CMake 时 我收到一条警告消息 Configuring done CMake Warning at CMakeLists txt 12 add executable Cannot generate a safe
  • 多线程进程的线程ID可以与另一个正在运行的进程的进程ID相同吗?

    我正在尝试找到一种方法来唯一标识多进程环境中的线程 我有一个服务器 它跟踪连接到它的不同进程 其中一些是多线程的 一些不是 为了识别多线程连接中的线程 我使用线程 ID 作为唯一标识符 在任何给定时间最多有 1 个多线程进程连接 我的问题是
  • Pthread互斥锁由不同线程解锁

    一个天真的问题 我之前读到过 MUTEX 只能由锁定它的线程解锁 但我写了一个程序THREAD1锁定 mutexVar 并进入睡眠状态 然后THREAD2可以直接解锁mutexVar做一些操作并返回 gt 我知道每个人都说我为什么要这样做
  • CMake - 未定义参考

    我正在尝试将 gtest 包含到我的项目中 问题是我在 GTest 中收到未定义的引用错误 我正在尝试在 Gtest 中测试 Node 类 在节点的构造函数中 我使用类记录器 尽管我已将库记录器添加到 gtest target 中 但我仍然
  • CMake、Exe找不到DLL

    所以我尝试在 Windows 上使用 cmake 设置一个项目 这就是我的项目结构 游戏引擎 git build include source testing CMakeLists txt 这个想法是 source 目录包含 GameEng
  • 如何使用cmake自动构建第三方库

    我在寻找什么 下载库 提取它 应用自定义补丁 运行配置 运行构建命令 我正在尝试构建的库是 Openssl Boost Thrift C ares Curl Pcre Nginx ICU JsonCPP 我想我可以使用外部模块做这些事情 h
  • 是否可以让 cmake 构建文件(CMakeLists.txt)不在 CLion 的根目录中

    是否可以让 cmake 构建文件 CMakeLists txt 不在 CLion 的根目录中 我目前正在开发的项目中 cmake 构建文件不在 CLion 项目的根目录中 在 out Debug 目录中 我希望 CLion 打开该项目的根目
  • 编译器标志的 cmake list 附加会产生虚假结果?

    我需要向 CMake 文件 CMake 2 8 10 2 中的 C 和 C 编译行添加各种标志 我看到有些人使用add definitions但据我所知 这是用于预处理器标志的 D 我有一些标志不想传递给预处理器 所以我一直在尝试修改CMA
  • CMake第三方库安装

    我是编程新手 对于我的研究项目 我需要安装一个第三方库以便与 CMake 一起使用 GitHub项目 https github com cpp io2d P0267 RefImpl blob master BUILDING md 我在我的电
  • CMake GUI:指定 Windows 的库路径

    我正在编译一个基于 CMake 的项目 具体来说是 SOCI 它依赖于 SQLite 这是Windows 没有可供项目研究的标准路径 因此它找不到SQLite 我在配置时得到这个 SQLite3 not found some librari
  • CMake:Fortran 模块和编译顺序

    我有一个大型 Fortran 程序 其中包含许多目录 每个目录都在伪库中单独编译 但仍然存在相互依赖的混乱 因此最终所有伪库都组合在一个可用的库中 我想使用 Fortran 模块 但它非常脆弱 因为我不能依赖自动依赖项检查 并且根据顺序编译
  • 即使不在 Windows 上,生成器表达式也会将 WIN32 变量计算为 true

    我在 Ubuntu 上工作 这是我的 CMake 代码的一部分 有问题的部分在最后一句中 include ExternalProject ExternalProject Add fftw3 external URL http www fft
  • 如何在cmake中静态链接到glibc

    我正在尝试从 Fedora 构建一个可以在 RedHat 6 机器上运行的包 所以我需要构建和静态链接一些RedHat机器中不存在的库 我发现我可以你 static libgcc or static libstdc 与标准库的静态版本链接
  • 如何配置 cmake 以链接到预构建的共享库?

    我有一个项目 在子目录中包含 opencv 的预构建版本 例如 我的项目 CMakeLists txt src 第三者 CMakeLists txt 开放式CV 包括 库 我想链接位于third party目录中的opencv版本 我的问题
  • 与 pthread 的进程间互斥

    我想使用一个互斥体 它将用于同步对两个不同进程共享的内存中驻留的某些变量的访问 我怎样才能做到这一点 执行该操作的代码示例将非常感激 以下示例演示了 Pthread 进程间互斥体的创建 使用和销毁 将示例推广到多个进程作为读者的练习 inc

随机推荐