【问题标题】:How to add the '-pthread' option to g++ via Eclipse?如何通过 Eclipse 向 g++ 添加“-pthread”选项?
【发布时间】:2014-02-10 17:57:25
【问题描述】:

我正在使用 eclipse 编译一个多线程库。

如何在 eclipse 对 g++ 的调用中添加 -pthread 或 -pthreads 选项?

【问题讨论】:

标签: eclipse gcc g++


【解决方案1】:

我差不多 2 年前写的原始答案现在已经过时了;这是今天的做法。

右键单击项目文件夹或文件>属性,然后C/C++构建>设置。在 GCC C++ Linker > Linker flags 添加 -pthread,最后点击 Apply 按钮。就是这样。

我在 Ubuntu 14.04 上使用 gcc 4.8 和 Eclipse Luna 对此进行了测试。感谢 Neil Traft 在comment 中指出这一点。



2014 年 2 月的原始答案,现已过时:

右键单击项目文件夹或文件>属性,然后C/C++构建>设置

GCC C++ Compiler > Miscellaneous-pthread 添加到 Other flags 并点击 Apply 按钮。

GCC C++ Linker > Libraries 点击 Libraries 栏上带有绿色加号的图标以添加 pthread,最后点击 Apply 按钮。

这个必须解决。

请注意,您必须告诉编译器和链接器您正在编译多线程应用程序(将-pthread 传递给编译器,将-lpthread 传递给链接器)。

【讨论】:

  • 据我所知,链接器的选项是-pthread,而不是-lpthread。我不知道这是否是“正确”的方法,但我通过转到 GCC C++ Linker > Miscellaneous 并输入 -pthread 让它工作在 链接器标志 框中。
  • @NeilTraft 我差不多 2 年前写了这个答案。显然,Eclipse 发生了变化,您不再拥有我所指的 Other flags。感谢您的反馈,我会尽快更新答案。
  • @NeilTraft 我已经对其进行了测试并相应地更新了答案。感谢您让我知道答案已过时!
  • 请将greed 更改为green。改动太小了,我不能编辑。
猜你喜欢
  • 1970-01-01
  • 2014-04-08
  • 2019-03-28
  • 2012-02-24
  • 1970-01-01
  • 2016-07-13
  • 1970-01-01
  • 1970-01-01
  • 2013-04-22
相关资源
最近更新 更多