Qt5编译添加gcc参数

ZC: 都是网上搜到的

 

1、

问题:

在linux下编写多线程,已经添加#include<pthread.h>头文件,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  -lrt  flag to cc in order to link

       against the required ("realtime") library.

 

       POSIX leaves the behavior of the combination of  O_RDONLY  and  O_TRUNC

       unspecified.   On  Linux,  this  will successfully truncate an existing

       shared memory object - this may not be so on other Unices.

 

       The POSIX shared memory object implementation on Linux 2.4 makes use of

a dedicated file system, which is normally mounted under /dev/shm.

 

如果你注意到的话,这样编译就能通过了:

gcc -lrt -o test test.c

其实就是要连接库的原因。

 

3、

4、

5、

 

转载于:https://www.cnblogs.com/LinuxCode/p/5444372.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值