我正试图学习c中的多线程程序,并得到了一个链接器错误,我无法解决我已经检查了类似于此的上一个问题,但这些解决方案可能没有解决我的问题。c线程程序中的链接器错误.. ld返回1退出状态
error :
single_thread.c:(.text+0x15)undefined reference to 'thread_function'
collect2:ld returned 1 exit status
我已经检查了错字的
的程序是这样的
#include<stdio.h>
#include<unistd.h>
#include<pthread.h>
#include<stdlib.h>
#include<string.h>
void *thread_functions(void *arg);
char message[]="Hello world";
int main()
{
int res;
pthread_t a_thread;
void *thread_res;
res=pthread_create(&a_thread,NULL,thread_functions,(void*)message);
//i guess error is from the function pointer.
if(res!=0)
{
perror("thread creation:");
exit(EXIT_FAILURE);
}
printf("waiting for thread to finish...\n");
pthread_join(a_thread,NULL);
/* if(res!=0)
{
perror("thread_join failed:");
exit(EXIT_FAILURE);
}*/
// printf("thread joined,it has returned %s\n",(char*)thread_res);
printf("Message:%s\n",message);
exit(EXIT_SUCCESS);
}
void *thread_fucntions(void *arg)
{
printf("thread function is running.argument was %s\n",(char*)arg);
sleep(3);
strcpy(message,"BYE!");
pthread_exit("thank you for the cpu time");
}
'我已经检查了错字的'...不知何故,我对此表示怀疑。 :) –
我有。用-lpthread编译代码。请帮助我提出问题的格式。我没有正确地得到它 – user3207191
在这段代码中似乎有一个类型,我想这是“void * thread_fucntions(void * arg)”这个问题在底部拼写错误。 – cedd