Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't link against Boost.Thread 1.46.1 with MinGW 4.5.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?

like image 317
jhasse Avatar asked Nov 30 '25 01:11

jhasse


1 Answers

Try adding the compiler option '-DBOOST_THREAD_USE_LIB'

like image 195
J T Avatar answered Dec 02 '25 14:12

J T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!