QT-x11-3.3.4
Redhat9
现有一QT GUI ,调用pthread线程,
使用qmake生成makefile文件后编译,错误如下:
thr.o(.text+0x14): In function `thr(int)':
: undefined reference to `pthread_create'
thr.o(.text+0x3c): In function `thr(int)':
: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make: *** [44] Error 1
thr.cpp代码如下:
- #include <pthread.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/io.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <termios.h>
- #include <sys/time.h>
- #include <errno.h>
- /* Main program */
- void *thread_send(void *arg);
- void *thread_result;
- char buf[250];
- int ressend,resrcv;
- int thr(int argc){
- pthread_t th;
- ressend=pthread_create(&th,NULL,thread_send,NULL);
-
- if(ressend!=0){
- perror("Thread filed");
- printf("send thread filed\n");
- exit(EXIT_FAILURE);
- }
- printf("thread start\n");
- ressend=pthread_join(th,&thread_result);
- if(ressend!=0){
- perror("Thread filed");
- printf("send thread filed\n");
- exit(EXIT_FAILURE);
- }
- exit(EXIT_SUCCESS);
- }
- void *thread_send(void *arg){
-
- printf("ok\n");
- pthread_exit(NULL);
- }
- #include <qapplication.h>
- #include "form1.h"
- int sh( int argc, char ** argv )
- {
- QApplication a( argc, argv );
- Form1 w;
- w.show();
- a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
- thr();
- return a.exec();
- }