当前位置: 技术问答>linux和unix
linux 线程问题c++,这是那错了啊!大家帮帮忙!!!!
来源: 互联网 发布时间:2016-05-14
本文导语: #include #include // exit(), EXIT_SUCCESS #include // pthread_create(),pthread_join() #include #include void * print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Hello"; char *message2 = "World"; pthread_creat...
#include
#include // exit(), EXIT_SUCCESS
#include // pthread_create(),pthread_join()
#include
#include
void * print_message_function( void *ptr );
main()
{
pthread_t thread1, thread2;
char *message1 = "Hello";
char *message2 = "World";
pthread_create(&thread1, NULL,
print_message_function, (void*) message1);
pthread_create(&thread2, NULL,
print_message_function, (void*) message2);
exit(0);
}
void * print_message_function( void *ptr )
{
char *message;
message = (char *) ptr;
printf("%s ", message);
}
错误是没有定义pthread_create
undefined referece to pthread_create 怎么会呢?
#include // exit(), EXIT_SUCCESS
#include // pthread_create(),pthread_join()
#include
#include
void * print_message_function( void *ptr );
main()
{
pthread_t thread1, thread2;
char *message1 = "Hello";
char *message2 = "World";
pthread_create(&thread1, NULL,
print_message_function, (void*) message1);
pthread_create(&thread2, NULL,
print_message_function, (void*) message2);
exit(0);
}
void * print_message_function( void *ptr )
{
char *message;
message = (char *) ptr;
printf("%s ", message);
}
错误是没有定义pthread_create
undefined referece to pthread_create 怎么会呢?
|
找不到线程库,编译的时候加上:
-lpthread
-lpthread