2

I've built boost using:

bjam --toolset=gcc --with-thread stage

Whenever I'm trying to actually use Boost.Thread I'm getting undefined references although I link against it. It doesn't happen with other Boost libraries like Regex or System.

>g++ main.cpp -I. -L. -lboost_thread-mgw45-mt-1_46_1
C:\Users\jhasse\AppData\Local\Temp\ccjYfDox.o:main.cpp:(.text+0xf): undefined reference to `_imp___ZN5boost6thread20hardware_concurrencyEv'
collect2: ld returned 1 exit status

Example program:

#include <boost/thread.hpp>
#include <iostream>

int main()
{
    std::cout << boost::thread::hardware_concurrency() << std::endl;
}

What am I doing wrong?

jhasse
  • 2,379
  • 1
  • 30
  • 40
  • 2
    Try adding the compiler option '-DBOOST_THREAD_USE_LIB' – J T Mar 29 '11 at 16:57
  • 2
    Hello, i just tried this method to use Boost and i get the linker error too, and when i use said compiler option, it gets moved to the #defines section of my options. Im using Code Blocks with MinGW and im using this option in `Compiler Settings->Other Options` – Molmasepic Jul 30 '11 at 02:33

1 Answers1

9

Try adding the compiler option '-DBOOST_THREAD_USE_LIB'

J T
  • 4,946
  • 5
  • 28
  • 38
  • 1
    +1; where is that documented? I can't find any notice about that in the boost thread 1.49 documentation. The boost 1.50 documentation has an unfinished sentence about defines in the top-level page about the thread library. – Christoph Jul 02 '12 at 21:33