GCC -lpthread不工作 [英] gcc -lpthread not working

查看:276
本文介绍了GCC -lpthread不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Ubuntu的安装11在我的系统。我有一个使用pthread库的C程序。
我得到的错误未定义参考sem_wait()即使我曾与标志编译 -lpthread

I have ubuntu 11 installed in my system. I have a c program that uses the pthread library. I get the error Undefined reference to sem_wait() even if I have compiled with the flag -lpthread.

例如:

gcc -lpthread prog.c

该项目工程罚款等Ubuntu的安装。

The program works fine on other ubuntu installations.

推荐答案

尝试:

gcc -pthread

而不是 -lpthread 。所不同的是显著,我相信。后者是链接到的的libpthread ,前者是针对连接和libpthread等等一堆其他的东西呢!

instead of -lpthread. The difference is significant, I believe. The latter is linking against libpthread, the former is linking against libpthread and a bunch of other things, too!

sem_wait 是librt的一部分,所以你也可以同样使用的gcc -lrt ,但 -pthread 这是否对你(以及其他一切的!)。

sem_wait is part of librt, so you could just as well use gcc -lrt, but -pthread does this for you (and everything else as well!).

这篇关于GCC -lpthread不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆