我需要-D_REENTRANT和-threads? [英] Do I need -D_REENTRANT with -pthreads?

查看:118
本文介绍了我需要-D_REENTRANT和-threads?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux(内核2.6.5)上,我们的构建系统调用gcc时使用 -D_REENTRANT

使用 pthreads



与<$ c $有什么关系c> gcc -pthread 选项?我知道我应该在pthreads中使用 -pthread ,是否还需要 -D_REENTRANT



在附注中,你知道gcc 3.3.3和gcc 4.xx之间REENTRANT的用法有什么不同吗?

当我使用 -pthread gcc选项时,我可以看到定义了 _REENTRANT 。从命令行中省略 -D_REENTRANT 会有什么不同,例如,某些对象是否可以在没有多线程支持的情况下编译,然后链接到使用pthreads的二进制文件中并导致问题?



我认为应该可以使用: g ++ -pthread

 >回声| g ++ -E -dM -c  - >单线程
>回声| g ++ -pthread -E -dM -c - >多线程
> diff单线程多线程
39a40
> #define _REENTRANT 1

我们正在编译多个与静态库链接的静态库和应用程序,库和应用程序使用pthreads。



我相信它在过去的某个阶段是必需的,但想知道它是否仍然是必需的。谷歌搜索没有返回任何最近的信息提及 - D_REENTRANT pthreads 。你能指出我的链接或参考文献讨论在 kernel / gcc / pthread 的最新版本中使用吗?



澄清:重新使用-D_REENTRANT和-lpthread,我假设我可以用g ++ -pthread替换它们,看着man gcc它为预处理器和链接器设置标志。任何想法?

解决方案

对于我来说,最好的答案是 pts 如果只是他打扰提交它作为答案:


您调查得当,并回答
您自己的问题。使用 g ++ -pthread
它相当于 g ++ -lpthread -D_REENTRANT
使用 g ++ -D_REENTRANT 可能不同,
可能不会设置所有链接器标志。 -
pts 5月18日0:30


On Linux (kernel 2.6.5) our build system calls gcc with -D_REENTRANT.

Is this still required when using pthreads?

How is it related to gcc -pthread option? I understand that I should use -pthread with pthreads, do I still need -D_REENTRANT?

On a side note, is there any difference that you know off between the usage of REENTRANT between gcc 3.3.3 and gcc 4.x.x ?

When I use -pthread gcc option I can see that _REENTRANT gets defined. Will omitting -D_REENTRANT from command line make any difference, for example could some objects be compiled without multithreaded support and then linked into binary that uses pthreads and will cause problems?

I assume it should be ok just to use: g++ -pthread

> echo | g++          -E -dM -c - > singlethreaded
> echo | g++ -pthread -E -dM -c - > multithreaded
> diff singlethreaded multithreaded
39a40
> #define _REENTRANT 1

We're compiling multiple static libraries and applications that link with the static libraries, both libraries and application use pthreads.

I believe it was required at some stage in the past but want to know if it is still required. Googling hasn't returned any recent information mentioning -D_REENTRANT with pthreads. Could you point me to links or references discussing the use in recent version of kernel/gcc/pthread?

Clarification: At the moment we're using -D_REENTRANT and -lpthread, I assume I can replace them with just g++ -pthread, looking at man gcc it sets the flags for both preprocessor and linker. Any thoughts?

解决方案

For me the best answer was the comment from pts if only he bothered to submit it as answer:

You investigated properly and answered your own question. Use g++ -pthread, it is equivalent to g++ -lpthread -D_REENTRANT. Using g++ -D_REENTRANT would be different, it may not set all the linker flags. – pts May 18 at 0:30

这篇关于我需要-D_REENTRANT和-threads?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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