编译时-pthread标志意义 - 海湾合作委员会 [英] gcc - significance of -pthread flag when compiling

查看:132
本文介绍了编译时-pthread标志意义 - 海湾合作委员会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在各种多线程的C和C ++项目我见过应用于编译和链接阶段均 -pthread 标志,而其他不使用它在所有与只是通过 -lpthread 来链接阶段。

In various multi threaded C and C++ projects I've seen the -pthread flag applied to both the compiling and linking stage while others don't use it at all and just pass -lpthread to the linking stage.

有没有编制,并与 -pthread 标志连接任何危险 - 即是什么 -pthread actully做?我primarly interrested在Linux平台。

Is there any danger not compiling and linking with the -pthread flag - i.e. what does -pthreadactully do ? I'm primarly interrested in linux platforms.

推荐答案

尝试:

gcc -dumpspecs | grep pthread

和寻找任何与开头%{pthread的:

在我的电脑上,这会导致文件与 -D_REENTRANT 进行编译,并与 -lpthread 链接。在其它平台上,这可能会有所不同。使用 -pthread 对于大多数的便携性。

On my computer, this causes files to be compiled with -D_REENTRANT, and linked with -lpthread. On other platforms, this could differ. Use -pthread for most portability.

使用 _REENTRANT ,在GNU libc的,更改某些的libc头的工作方式。作为一个具体的例子,它使错误号调用一个函数返回一个线程本地的位置。

Using _REENTRANT, on GNU libc, changes the way some libc headers work. As a specific example, it makes errno call a function returning a thread-local location.

这篇关于编译时-pthread标志意义 - 海湾合作委员会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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