2011-03-22 69 views
5

我在linux下UBUNTU下工作在eclipse 10.10,使用Synaptic pkg管理器安装boost-dev软件包1.40。我是Linux新手,这个提升pkg。我尝试创建一个新的项目,并写上:不能编译,如果包括提升/线程在Linux Ubuntu 10.10

#include <boost/thread.hpp> 
int main(int argc, char* argv[]){ 
} 

我不包括任何东西,或任何地方写这样并行线程东西。 试图建立的时候,它说:

/usr/include/boost/config/requires_threads.hpp:47: error: #error "Compiler threading support is not turned on. Please set the correct command line options for threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)" 
In file included from /usr/include/boost/thread/thread.hpp:12, 
       from /usr/include/boost/thread.hpp:13, 
       from ../main.cpp:8: 
/usr/include/boost/thread/detail/platform.hpp:67: error: #error "Sorry, no boost threads are available for this platform." 
In file included from /usr/include/boost/thread.hpp:13, 
       from ../main.cpp:8: 
/usr/include/boost/thread/thread.hpp:19: error: #error "Boost threads unavailable on this platform" 

等等,很多相关的多个错误的提振。 我试图将-pthread,-pthreads,-lpthread添加到我认为可以的地方,但没有解决问题。 我忘了提及,我试图在eclipse中构建项目,我不在命令行工作,但我也尝试了g ++ -pthread main.cpp,它给出了完全相同的错误。 请详细说明或stepbystep解决方案,因为您在这里回答的一些问题对我来说只是中文。我只想让一件简单的事情运行,甚至不理解问题。甚至不明白那个错误信息,它要我做什么。 基本上我做了:安装eclipse,将上述内容写入新项目,使用sinaptic pkg管理器安装libboost 1.4,并重新启动所有内容并尝试编译。我得到了错误。看不到发生了什么,或者我错过了什么。 (我有libc-dev) 堆栈现在真的流淌了。需要一些睡眠来降温。谢谢你们的帮助!

+1

哇,那是我第一次听说过Linux的称为Linux 10.10。毫无疑问,Ubuntu肯定会产生一些影响。 :-) – Shinnok 2011-03-22 10:58:43

+0

对不起,我是新来的所有这些Linux和Ubuntu的东西,但是,是的,这是一个错误:)有趣,虽然 – andrissh 2011-03-22 11:15:03

+0

显示您的编译命令行完全在你的问题。 Boost线程只是包装底层的OS线程,所以通过包含boost/thread.hpp来请求pthreads。 – Duck 2011-03-22 13:14:31

回答

2

由于错误信息说:传-pthread编译器:

g++ -pthread yourfile.cpp 

另外,Debian,请确保你已经安装了libc-dev

+0

谢谢,它试过这个,但它提供了完全相同的消息 - 这次它将它写入终端当然。我想知道,我如何在eclipse中运行而不是终端。 /usr/include/boost/config/requires_threads.hpp:47:error:#error“编译器线程支持未打开,请为线程设置正确的命令行选项:-pthread(Linux),-pthreads(Solaris)或-mthreads(Mingw32)“ – andrissh 2011-03-22 10:45:13

+0

我有libc-dev。任何其他提示? – andrissh 2011-03-22 11:13:15

6
#include <boost/thread.hpp> 

int main(int argc, char *argv[]) { 
    return 0; 
} 

编译g++ test.cpp -pthread -lboost_thread

+0

感谢您的提示!完全相同的错误! (我看到你添加了返回0 :) – andrissh 2011-03-22 14:29:42

+0

你的软件包肯定有东西坏了。尝试重新安装boost和g ++。 – orlp 2011-03-22 14:31:19

+0

嗯。试过也...同样的错误。我应该现在安装10.04而不是10.10? – andrissh 2011-03-22 15:00:38

11

这个问题是一个众所周知的从这样一个旧版本的提升。您正在使用gcc/g ++ 4.7进行编译,其中对pthread的引用已更改为GLIBCXX_HAS_GTHREADS,因此boost无法找到pthread并将其禁用。

所以,你有两个选择:

1)升级boost_dev到最后一个版本(我认为这是固定的1.50+)。

2)修补你的boost包含文件(我已经完成了这个);只需编辑

“你升压文件夹” /include/config/stdlib/libstdcpp3.hpp

和变化:

#ifdef __GLIBCXX__ // gcc 3.4 and greater: 
# if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \ 
     || defined(_GLIBCXX__PTHREADS) 
     // 
     // If the std lib has thread support turned on, then turn it on in Boost 
     // as well. We do this because some gcc-3.4 std lib headers define _REENTANT 
     // while others do not... 
     // 
#  define BOOST_HAS_THREADS 
# else 
#  define BOOST_DISABLE_THREADS 
# endif 

添加新的指令中的条件:

#ifdef __GLIBCXX__ // gcc 3.4 and greater: 
# if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \ 
     || defined(_GLIBCXX__PTHREADS) \ 
     || defined(_GLIBCXX_HAS_GTHREADS) // gcc 4.7 
     // 
     // If the std lib has thread support turned on, then turn it on in Boost 
     // as well. We do this because some gcc-3.4 std lib headers define _REENTANT 
     // while others do not... 
     // 
#  define BOOST_HAS_THREADS 
# else 
#  define BOOST_DISABLE_THREADS 
# endif 

错误描述和修复的Linux和Windows在这里:

https://svn.boost.org/trac/boost/ticket/6165

享受。

3

您需要安装升压线程库:

sudo apt-get install libboost-thread-dev