ubuntu 12.10 多线程编译的问题
发表于 : 2013-02-20 11:32
happyboy@happyboy-hp:~/workspace/c/apue/thread$ gcc -o printid -L/usr/lib/x86_64-linux-gnu/ -lpthread printid.c
/tmp/ccpZr1ny.o:在函数‘print_id’中:
printid.c:(.text+0x15):对‘pthread_self’未定义的引用
/tmp/ccpZr1ny.o:在函数‘main’中:
printid.c:(.text+0x81):对‘pthread_create’未定义的引用
collect2: 错误: ld 返回 1
对应的动态库文件是存在,为何还编译还报错呢?
happyboy@happyboy-hp:~/workspace/c/apue/thread$ ls -l /usr/lib/x86_64-linux-gnu/libpthread
libpthread.a libpthread_nonshared.a libpthread.so
看了下libpthread.so 其内容如下:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib/x86_64-linux-gnu/libpthread.so.0 /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a )
/tmp/ccpZr1ny.o:在函数‘print_id’中:
printid.c:(.text+0x15):对‘pthread_self’未定义的引用
/tmp/ccpZr1ny.o:在函数‘main’中:
printid.c:(.text+0x81):对‘pthread_create’未定义的引用
collect2: 错误: ld 返回 1
对应的动态库文件是存在,为何还编译还报错呢?
happyboy@happyboy-hp:~/workspace/c/apue/thread$ ls -l /usr/lib/x86_64-linux-gnu/libpthread
libpthread.a libpthread_nonshared.a libpthread.so
看了下libpthread.so 其内容如下:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib/x86_64-linux-gnu/libpthread.so.0 /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a )