Ziggo-CaaS-Switch软件配置: undefined reference to pthread_create

Ziggo-CaaS-Switch软件配置编译错误:

88% Built target time_sync_app

Scanning dependencies of target time_sync

91% Building C object CMakeFiles/time_sync.dir/time_sync_main_loop.c.o

94% Linking C executable time_sync

/usr/bin/ld: CMakeFiles/time_sync.dir/time_sync_main_loop.c.o: in function `main':

time_sync_main_loop.c:(.text+0x1be3): undefined reference to `pthread_create'

collect2: error: ld returned 1 exit status

make2: *** CMakeFiles/time_sync.dir/build.make:85: time_sync Error 1

make1: *** CMakeFiles/Makefile2:80: CMakeFiles/time_sync.dir/all Error 2

make: *** Makefile:84: all Error 2

**错误分析:**pthread_create 属于线程库,当前链接 time_sync 时没有把线程库真正带进去,所以在最后 ld 阶段失败。其实,undefined reference to pthread_create 是典型的"编译时带了 -lpthread,但链接阶段没有正确链接线程库"的问题。你这个仓库的 CMakeLists.txt 把 -lpthread 塞进了 CMAKE_C_FLAGS,这并不可靠,尤其在可执行文件链接阶段经常失效。

解决步骤:

直接改交换机软件目录下的 CMakeLists.txt:

xx/Ziggo-CaaS-Switch-main/Ziggo-CaaS-Switch-main/Software/Time-Synchronization/CMakeLists.txt

把末尾这两段:

bash 复制代码
add_executable(time_sync time_sync_main_loop.c)
target_link_libraries(time_sync ${PROJECT_NAME})

add_executable(switch_config switch_config_main.c)
target_link_libraries(switch_config ${PROJECT_NAME})

改成更稳妥的写法:

bash 复制代码
find_package(Threads REQUIRED)

add_executable(time_sync time_sync_main_loop.c)
target_link_libraries(time_sync ${PROJECT_NAME} Threads::Threads m)

add_executable(switch_config switch_config_main.c)
target_link_libraries(switch_config ${PROJECT_NAME} Threads::Threads m)

如果你的环境里 Threads::Threads 解析有问题,也可以先用简单版本:

bash 复制代码
target_link_libraries(time_sync ${PROJECT_NAME} pthread m)
target_link_libraries(switch_config ${PROJECT_NAME} pthread m)

然后重新构建,最好清掉原来的 build 目录重新跑一遍:

bash 复制代码
cd /path/to/Software/Time-Synchronization
rm -rf build
mkdir build
cd build
cmake ..
make -j
相关推荐
深入云栈1 小时前
Netty 4.2.x 源码深度解析 (二十三):ByteBuf 核心设计 —— 索引、类型与零拷贝
java·后端·架构
爱笑的k111 小时前
nano-vllm 源码剖析:千行 Python 手写离线推理引擎的调度、显存与并行时序
开发语言·python·vllm
wang_shu_mo_ran2 小时前
MyBatis 从入门到进阶(一)
java·spring·mybatis
X1A0RAN3 小时前
PPT 图片批量处理教程:导出全部幻灯片 · 提取全部素材
开发语言·javascript·powerpoint
量化分析码农3 小时前
股票历史数据的复权参数对照:多级别返回的字段与数值差异
java·javascript·后端
猫猫不是喵喵.4 小时前
从0到1创建一个微服务项目
java·数据库·微服务·1024程序员节
熊猫钓鱼>_>4 小时前
普通用户视角的端侧智能体验手记【鸿蒙心迹】
开发语言·人工智能·华为·智能手机·性能优化·ai编程·harmonyos
瑞雪兆丰年兮4 小时前
JavaWeb-day13-SpringBootWeb事务管理&AOP
java·开发语言·springboot·javaweb·事务·web·aop
曲径海盗4 小时前
Try-Except怎么用,3个追问解答在自动化下的应用
java·jvm·oracle
Cosolar5 小时前
极简智库:快速搭建你的开源项目教程阅读平台,让 docs/ 目录被更多人看见
java·架构·github