gcc 编译问题 请高手指点

软件和网站开发以及相关技术探讨
回复
头像
s4426565
帖子: 34
注册时间: 2007-10-24 1:37

gcc 编译问题 请高手指点

#1

帖子 s4426565 » 2008-01-21 22:11

我写了一段程序如下

#include<pthread.h>
#include<stdio.h>
void* threadFunction(void* input);
int loop = 0;

int main( int argc , char **argv)
{
pthread_t t1;
pthread_create(&t1,NULL,threadFunction,NULL);

printf("Thread_erzeugt\n");
pthread_join(t1,NULL);

return 0;
}

void* threadFunction(void* input)
{
while(loop<10)
{
printf("Nummer:_%d\n",loop);
loop++;
}
return NULL;
}

命名为 versuch1.c
运行 gcc versuch1.c /usr/lib/libpthread.a -o versuch1
error 为:


/usr/lib/libpthread.a(pthread_create.o): In function `allocate_stack':
/build/buildd/glibc-2.6.1/build-tree/glibc-2.6.1/nptl/allocatestack.c:411: undefined reference to `_dl_stack_flags'
/build/buildd/glibc-2.6.1/build-tree/glibc-2.6.1/nptl/allocatestack.c:547: undefined reference to `_dl_stack_flags'
/usr/lib/libpthread.a(ptw-pause.o): In function `__pause_nocancel':
(.text+0x18): undefined reference to `__syscall_error'
/usr/lib/libpthread.a(ptw-pause.o): In function `__pause_nocancel':
(.text+0x3b): undefined reference to `__syscall_error'
/usr/lib/libpthread.a(init.o): In function `__pthread_initialize_minimal_internal':
/build/buildd/glibc-2.6.1/build-tree/glibc-2.6.1/nptl/init.c:264: undefined reference to `__libc_setup_tls'
/build/buildd/glibc-2.6.1/build-tree/glibc-2.6.1/nptl/init.c:387: undefined reference to `_dl_init_static_tls'
/build/buildd/glibc-2.6.1/build-tree/glibc-2.6.1/nptl/init.c:389: undefined reference to `_dl_wait_lookup_done'
/usr/lib/libpthread.a(ptw-read.o): In function `__read_nocancel':
(.text+0x26): undefined reference to `__syscall_error'
/usr/lib/libpthread.a(ptw-read.o): In function `__read_nocancel':
(.text+0x56): undefined reference to `__syscall_error'
/usr/lib/libpthread.a(ptw-open.o): In function `__open_nocancel':
(.text+0x26): undefined reference to `__syscall_error'
/usr/lib/libpthread.a(ptw-open.o): In function `__open_nocancel':
(.text+0x56): undefined reference to `__syscall_error'
/usr/lib/libpthread.a(sigaction.o): In function `__libc_sigaction':
/build/buildd/glibc-2.6.1/build-tree/glibc-2.6.1/nptl/../sysdeps/unix/sysv/linux/i386/sigaction.c:83: undefined reference to `_dl_sysinfo_dso'
collect2: ld returned 1 exit status


不知道为什么编译不了 看上去我已经连接了正确的库
A man travels the world in search of what he needs and returns home to find it
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#2

帖子 iblicf » 2008-01-21 23:20

gcc -lpthread what.c
头像
s4426565
帖子: 34
注册时间: 2007-10-24 1:37

#3

帖子 s4426565 » 2008-01-22 17:32

谢谢 iblicf 问题解决了 我看了man gcc 里面好像没有你写的这个参数 这个参数的意思吗 为什么不用指定库的路径就可以直接连接到那里
A man travels the world in search of what he needs and returns home to find it
头像
hubert_star
论坛版主
帖子: 5373
注册时间: 2007-10-29 22:12
系统: OSX 10.9 + Ub 1304
来自: 江苏南京

#4

帖子 hubert_star » 2008-01-22 17:35

现在的内核默认不是pthread线程,你要指明用才行
佛经说,人有八苦: 生、老、病、死、求不得、怨憎、爱别离、五阴盛 故我苦!
圣经说,人有七罪: 饕餮、贪婪、懒惰、淫欲、傲慢、嫉妒和暴怒  故我有罪!

我这篇帖子里面没有任何攻击我们伟大的中华人民共和国政府和任劳任怨的人民公仆(和本论坛高素质的版主)的文字和含义;

特此声明!

有些事,我们明知道是错的,也要去坚持,因为不甘心;有些人,我们明知道是爱的,也要去放弃,因为没结局;有时候,我们明知道没路了,却还在前行,因为习惯了。

欢迎来我的新浪微博@me
头像
s4426565
帖子: 34
注册时间: 2007-10-24 1:37

#5

帖子 s4426565 » 2008-01-22 18:41

hubert_star 写了:现在的内核默认不是pthread线程,你要指明用才行
我也是这样想的 不过 iblicf 说的真的是可以用的 我在suse10。3 和 ubuntu7。10 上面都试过 不管你在 home/username 还是在 home/username/destop 下都可以编译成功 真的

我做的步骤如下:
lei@linux:~> ls
backup Desktop Downloads Music public_html
bin Documents file: nautilus-debug-log.txt versuch1.c
lei@linux:~> gcc -lpthread versuch1.c
lei@linux:~> ls
a.out bin Documents file: nautilus-debug-log.txt versuch1.c
backup Desktop Downloads Music public_html
lei@linux:~> ./a.out
Thread_erzeugt
Nummer:_0
Nummer:_1
Nummer:_2
Nummer:_3
Nummer:_4
Nummer:_5
Nummer:_6
Nummer:_7
Nummer:_8
Nummer:_9
lei@linux:~>
A man travels the world in search of what he needs and returns home to find it
头像
qlhn
帖子: 736
注册时间: 2006-08-25 10:37
联系:

#6

帖子 qlhn » 2008-02-02 14:01

见到高手了,赞一个!
回复