ZC: 都是网上搜到的
1、
问题:
在linux下编写多线程,已经添加#include头文件,qt编译器提示: error: undefined reference to `pthread_create'。
经过百度,得知:“pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。”
所以,解决方法是:“在编译中要加 -lpthread参数(gcc thread.c -o thread -lpthread)”。
问题是,我不想在终端单独打gcc命令,而是希望能在qtcreator中直接编译。请问该如何设置(添加上这一个-lpthread的后缀)?
解决方法是:
在多线程那个项目的 .pro文件 中添加:LIBS += -lpthread 。
2、
问题:
undefined reference to `shm_open'
undefined reference to `shm_unlink'
解决:
注意一下man shm_open的帮助文件的最后几行:
NOTES
These functions are provided in glibc 2.2 and later. Programs using
these functions must specify the