Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doesn't compile if included boost/thread in linux Ubuntu:)10.10

I work in eclipse under linux UBUNTU:) 10.10, installed the boost-dev packages 1.40 using the Synaptic pkg manager. I am new to linux and this boost pkg. I try to create a new project, and write:

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

I did not include anything or write anything like pthread anywhere. when trying to build, it says:

/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"

and so on, a lot of more errors related to boost. I tried to add -pthread, -pthreads, -lpthread to where I thought I could, but did not solve the problem. I forgot to mention, that I try to build the project in eclipse, I don't work in the command line, but I also tried g++ -pthread main.cpp and it gives the exact same error. Please give detailed or stepbystep solution, because some things you answer here are simply chinese to me. I just want to get a simple thing running and don't even understand the problem. Don't even understand that error message, what does it want me to do. basically what I did: install eclipse, write the above things in a new project, install libboost 1.4 using sinaptic pkg manager, and restarted everything and tried to compile. I got the error. Don't see what's happening, or what am I missing. (I have libc-dev) Stack is really flowing over now. need some sleep to cool down. thank you guys for help!

like image 963
andrissh Avatar asked Mar 22 '11 10:03

andrissh


1 Answers

The issue is a well known one from such an old version of boost. You are compiling with gcc/g++ 4.7, where the reference to pthreads have changed to GLIBCXX_HAS_GTHREADS, so boost is unable to find pthreads and disable it.

So you have two options:

1) Upgrade boost_dev to last release (I think it's fixed in 1.50+).

2) Patch your boost include files (I've done this); just edit

"your boost folder"/include/config/stdlib/libstdcpp3.hpp

and change:

#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

to add the new directive in the condition:

#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

Bug description and fixes for linux and windows here:

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

Enjoy.

like image 152
Alberto Avatar answered Oct 09 '22 03:10

Alberto