当前位置: 技术问答>linux和unix
线程问题(IBM H85系列)?
来源: 互联网 发布时间:2015-03-28
本文导语: 各位大侠,帮忙看看代码: 错误提示: 0711-317 ERROR: Undefined symbol: .pthread_create 代码如下: #include #include #include #include #include #include #include #include #include #include #include #include struct sockaddr_in server...
各位大侠,帮忙看看代码:
错误提示: 0711-317 ERROR: Undefined symbol: .pthread_create
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct sockaddr_in server,reply;
char sendbuf[]="(((";
#define PORT 2000
struct ARG{
int connfd;
struct sockaddr_in server;
} ;
void process_sendxh(int connectfd,struct sockaddr_in server);
void* start_sendxh(void* arg);
void main(int argc,char *argv[])
{
int fd;
struct hostent *he;
struct sockaddr_in server;
struct ARG *arg,midarg;
pthread_t lthread,thr;
int len;
if(argc !=2){
printf("Usage:%s n",argv[0]);
exit(1);
}
if((he=gethostbyname(argv[1]))==NULL){
printf("gethostbyname() errorn");
exit(1);
}
if((fd=socket(AF_INET,SOCK_DGRAM,0))==-1){
printf("socket() errorn");
exit(1);
}
memset(&server,0,sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
arg = &midarg;
arg->connfd = fd;
memcpy((void*)&arg->server,&server,sizeof(server));
if (pthread_create(<hread,NULL,start_sendxh,(void*)arg)){
perror("pthread_cread ((( error!");
exit(1);
}
pthread_exit;
}
void* start_sendxh(void* arg)
{
struct ARG* info;
info = (struct ARG *)arg;
printf("You Start send thread n");
process_sendxh(info->connfd,info->server);
pthread_exit;
}
void process_sendxh(int connectfd,struct sockaddr_in server)
{
while (1)
{
if (sendto(connectfd,sendbuf,strlen(sendbuf),0,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){
perror("Send ((( error Send thread stop! n");
break;
}
printf("Send message ((( to server n");
sleep(20);
}
}
错误提示: 0711-317 ERROR: Undefined symbol: .pthread_create
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct sockaddr_in server,reply;
char sendbuf[]="(((";
#define PORT 2000
struct ARG{
int connfd;
struct sockaddr_in server;
} ;
void process_sendxh(int connectfd,struct sockaddr_in server);
void* start_sendxh(void* arg);
void main(int argc,char *argv[])
{
int fd;
struct hostent *he;
struct sockaddr_in server;
struct ARG *arg,midarg;
pthread_t lthread,thr;
int len;
if(argc !=2){
printf("Usage:%s n",argv[0]);
exit(1);
}
if((he=gethostbyname(argv[1]))==NULL){
printf("gethostbyname() errorn");
exit(1);
}
if((fd=socket(AF_INET,SOCK_DGRAM,0))==-1){
printf("socket() errorn");
exit(1);
}
memset(&server,0,sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
arg = &midarg;
arg->connfd = fd;
memcpy((void*)&arg->server,&server,sizeof(server));
if (pthread_create(<hread,NULL,start_sendxh,(void*)arg)){
perror("pthread_cread ((( error!");
exit(1);
}
pthread_exit;
}
void* start_sendxh(void* arg)
{
struct ARG* info;
info = (struct ARG *)arg;
printf("You Start send thread n");
process_sendxh(info->connfd,info->server);
pthread_exit;
}
void process_sendxh(int connectfd,struct sockaddr_in server)
{
while (1)
{
if (sendto(connectfd,sendbuf,strlen(sendbuf),0,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){
perror("Send ((( error Send thread stop! n");
break;
}
printf("Send message ((( to server n");
sleep(20);
}
}
|
"我用的编译命令是:
cc -pthread testthread.c
应该没错,加上-pthread ,会不会还是找不到真正的连接库?,我看了pthread.h文件的确存在。
谁来帮我?"
同意楼上应该是-lpthread ,头文件不用在编译时加载的。
cc -pthread testthread.c
应该没错,加上-pthread ,会不会还是找不到真正的连接库?,我看了pthread.h文件的确存在。
谁来帮我?"
同意楼上应该是-lpthread ,头文件不用在编译时加载的。
|
对你使用的系统没认识。
不知道你是否加了-lpthread类似的东西?
不知道你是否加了-lpthread类似的东西?
|
应该是:cc -lpthread testthread.c,你漏掉了l