LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1055|回复: 6

using thread, link error.

[复制链接]
发表于 2003-8-16 10:42:18 | 显示全部楼层 |阅读模式
  1. gcc -lpthread -o thread thread.c
  2. /tmp/ccj55W69.o(.text+0x44): In function `scanhost':
  3. : undefined reference to `pthread_mux_lock'
  4. /tmp/ccj55W69.o(.text+0x83): In function `scanhost':
  5. : undefined reference to `pthread_mut_unlock'
  6. /tmp/ccj55W69.o(.text+0x6c4): In function `main':
  7. : undefined reference to `create_thread'
  8. collect2: ld returned 1 exit status
  9. make: *** [thread] Error 1
复制代码

How come?
发表于 2003-8-16 12:36:47 | 显示全部楼层
没有连接上库。看看你的库文件路径设置有无问题。
 楼主| 发表于 2003-8-16 16:24:57 | 显示全部楼层
All because I compiled gcc2.59.3?

I don't know how to check.
发表于 2003-8-17 02:49:07 | 显示全部楼层
: undefined reference to `pthread_mux_lock'
/tmp/ccj55W69.o(.text+0x83): In function `scanhost':
: undefined reference to `pthread_mut_unlock'
/tmp/ccj55W69.o(.text+0x6c4): In function `main':
: undefined reference to `create_thread'  >>>pthread_create
?????????????

这几个函数都写错了 用google查查缓程库中对应函数的函数名
 楼主| 发表于 2003-8-17 09:44:06 | 显示全部楼层
Ha,Ha.
I thought I didn't get the compile error. So I think this code is correct.
发表于 2003-8-17 11:37:52 | 显示全部楼层
你的thread 库文件在那个目录下,如果是在/usr/local/lib下,就检查一下在/etc/ld.so.conf中有没有这个路径。如果没有就加上,然后执行ldconfig。
发表于 2003-8-17 21:34:49 | 显示全部楼层
pthread库中创建线程的函数是pthread_create

创建其它的函数你可以看它的man
也可以使用nm 看libpthread的符号看看

编译不出问题并不表示你使用的是对的
如我声明了一个函数但没有实现它 这是训练班译时也不出错
但是连接时会出错
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表