编译加了 -lpthread 还是有 undefined reference to `pthread_create'咋整???

w22net 2015-02-23 11:27:50
编译加了 -lpthread 还是有 undefined reference to `pthread_create'咋整???

book@ubuntu:/work/linuxStd/thread/9-2-1-1$ make
gcc -I. -D_REENTRANT -I/usr/include/nptl -L/usr/lib/nptl -lpthread -g -o thread thread.o
thread.o: In function `main':
/work/linuxStd/thread/9-2-1-1/thread.c:43: undefined reference to `pthread_create'
/work/linuxStd/thread/9-2-1-1/thread.c:55: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make: *** [thread] Error 1
...全文
1670 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
w22net 2015-02-25
  • 打赏
  • 举报
回复
引用 5 楼 baidu_24256693 的回复:
不知道-lpthread应该在编译生成.o文件的时候加,还是在.o文件生成可执行文件的时候加 你可以试试在生成.o文件的时候加上-lpthread
找到问题! 确实是应该在生成. o文件后加 把 -lpthread 移到${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} 就没问题了 点赞
fly 100% 2015-02-25
  • 打赏
  • 举报
回复
依赖 include pthread.h
  • 打赏
  • 举报
回复
引用 7 楼 w22net 的回复:
[quote=引用 5 楼 baidu_24256693 的回复:] 不知道-lpthread应该在编译生成.o文件的时候加,还是在.o文件生成可执行文件的时候加 你可以试试在生成.o文件的时候加上-lpthread
找到问题! 确实是应该在生成. o文件后加 把 -lpthread 移到${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} 就没问题了 点赞。[/quote] 很高兴能帮到你
  • 打赏
  • 举报
回复
不知道-lpthread应该在编译生成.o文件的时候加,还是在.o文件生成可执行文件的时候加 你可以试试在生成.o文件的时候加上-lpthread
w22net 2015-02-23
  • 打赏
  • 举报
回复
我的makefile EXEC = thread OBJS = thread.o HEADERS = CC = gcc INC = -I. CFLAGS = ${INC} -D_REENTRANT -I/usr/include/nptl -L/usr/lib/nptl -lpthread -g all:${EXEC} ${EXEC} : ${OBJS} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${OBJS} : ${HEADERS} .PHONY : clean clean : -rm -f ${OBJS} ${EXEC}
  • 打赏
  • 举报
回复
引用 1 楼 baidu_24256693 的回复:
写了头文件没有#include<pthread.h>
把你的makefile贴出来看看,也许是makefile有问题
w22net 2015-02-23
  • 打赏
  • 举报
回复
有 #include <pthread.h> 啊
  • 打赏
  • 举报
回复
写了头文件没有#include<pthread.h>
opencv2.4.4移植到ARM 一、编译环境及库文件 linux环境:ubuntu 11.10 交叉编译:4.6.1 opencv: opencv-2.4.4 cmake: cmake-2.8.1-Linux-i386.tar.gz 二、opencv-2.4.4的移植过程 解压cmake-2.8.1-Linux-i386.tar.gz到/usr/local/ cmake-2.8.1 #export PATH= /usr/local/ cmake-2.8.1/bin:$PATH 用到的主要目录说明: 交叉编译工具链所在目录 /usr/local/arm-4.6.1/ 安装opencv的目录 /usr/local/ opencv源码所在目录 /usr/local /opencv-2.4.4 编译好的opencv库所在目录 /usr/local /opencv-2.4.4/build 默认安装目录为/usr/local #mkdir build #cd build #cmake-gui 选择源代码目录 /usr/local /opencv-2.4.4 选择Build目录 /usr/local /opencv-2.4.4/build 点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next, Operating System填写arm-linux C Compilers填写/usr/local/arm-4.6.1//bin/arm-none-linux-gnueabi-gcc C++ Compilers填写/usr/local/arm-4.6.1//bin/ arm-none-linux-gnueabi -g++ 程序库的Target Root填写/usr/local/arm-4.6.1/ 然后点击Finish,开始configure 点击Generate生成Makefile(等configure完之后按钮才能点击) #make 错误一: Linking CXX executable ../../bin/opencv_createsamples ../../lib/libopencv_core.so: undefined reference to `clock_gettime' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFerrorHandler' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFrealloc' ../../lib/libopencv_core.so: undefined reference to `pthread_key_create 解决方法: 修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,上-lpthread -lrt,重新编译,错误消除 错误二: Linking CXX executable ../../bin/opencv_createsamples ../../lib/libopencv_highgui.so: undefined reference to `_TIFFerrorHandler' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFrealloc' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFmalloc' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemcpy' ../../lib/libopencv_highgui.so: undefined reference to `TIFFOpen' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFfree' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFwarningHandler' ../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemcmp' ../../lib/libopencv_high

23,223

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧