qt中使用pthread的undefined错误

来源:互联网 发布:odn网络 s r什么意思 编辑:程序博客网 时间:2024/06/01 15:57

pthread的库不是Linux系统的库,所以在使用gcc或g++进行编译的时候要加上-lpthread

g++ -o test main.cpp -lpthread

在qt中使用时也要将库添加进去,如果不添加会出现undefined reference错误。如下:

/home/qt-project/First_qt/main.cpp:18: error: undefined reference to `pthread_create'/home/qt-project/First_qt/main.cpp:25: error: undefined reference to `pthread_join':-1: error: collect2: error: ld returned 1 exit status

添加方法,打开.pro文件,在后面添加一行
注:我用的gmake

LIBS += -lpthread

如果库没包含在默认目录那么就这么加

//库路径:/home/pthreadlib/Pre-built.2/lib//在QT中指定库的路径:LIBS += -L/home/pthreadlib/Pre-built.2/lib -lpthread
阅读全文
0 0
原创粉丝点击