User forums > Using Code::Blocks

SOLVED - Linker errors - boost::thread (version 1.52), tdm-gcc (version 4.7.1)

(1/1)

herrtool:
Edit: I can't remove this post/topic.  I've change the topic title to include "SOLVED."  Maybe someone else will find it useful (or feel free to remove the topic).

I've been using Code::Blocks for Windows since version 10.12 with TDM-GCC version 4.5.2 (a MinGW compiler).  Everything was working fine.  I decided to do a much needed upgrade of Code::Blocks, Boost, and the gcc compiler I had been using this weekend.  Unfortunately, I'm getting some linker errors for the thread library and I haven't been able to get it figured out.

This might be a problem that would be better addressed on the boost forum but I figure I'll cover my bases and make sure this is not a problem with how I've been using Code::Blocks.

I built boost 1.52 last night with something along the lines of

--- Code: ---b2 --toolset=gcc --build-type=minimal link=static threading=multi stage
--- End code ---

That went fine.

It's installed at C:\boost\boost_1_52_0.  Headers are in C:\boost\boost_1_52_0\boost and libs are at C:\boost\boost_1_52_0\stage\lib.

I set up the global compiler variable for boost as
name: boost
base: c:\boost
include: c:\boost\boost_1_52_0\
lib: c:\boost\boost_1_52_0\stage\lib

This is not so different from how it was configured with Code::Blocks v10.12 and boost 1.47 (and tdm-gcc 4.5.2, if that matters).

Here's my sample program

--- Code: ---#include <iostream>
#include <boost/regex.hpp>
#include <boost/thread.hpp>

int main(int argc, char** argv)
{
  boost::regex reg("^.*$");
  boost::thread t;
  system("PAUSE");
  return 0;
}

--- End code ---

Compiler output (building debug):

--- Code: ---obj\Debug\main.o||In function `main':|
C:\Projects\MUD Concepts\TestNewCB12\Test\main.cpp|8|undefined reference to `_imp___ZN5boost6threadC1Ev'|
obj\Debug\main.o||In function `ZN5boost6threadD1Ev':|
C:\boost\boost_1_52_0\boost\thread\detail\thread.hpp|179|undefined reference to `_imp___ZN5boost6thread6detachEv'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 1 seconds) ===|

--- End code ---

Project level build options (i.e., not just on debug or release tree node)

Linker Settings:
Link Libraries:
libboost_thread-mgw47-mt-d-1_52.a
libboost_system-mgw47-mt-d-1_52.a
libboost_regex-mgw47-mt-d-1_52.a

Search Directories:
Compiler:
$(#boost.include)
Linker:
$(#boost.lib)

Build log:

--- Code: ----------------- Build: Debug in Test (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\boost\boost_1_52_0\stage\lib  -o Test.exe obj\Debug\main.o    -lboost_thread-mgw47-mt-d-1_52 -lboost_system-mgw47-mt-d-1_52 -lboost_regex-mgw47-mt-d-1_52
obj\Debug\main.o: In function `main':
C:/Projects/MUD Concepts/TestNewCB12/Test/main.cpp:8: undefined reference to `_imp___ZN5boost6threadC1Ev'
obj\Debug\main.o: In function `ZN5boost6threadD1Ev':
C:/boost/boost_1_52_0/boost/thread/detail/thread.hpp:179: undefined reference to `_imp___ZN5boost6thread6detachEv'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings (0 minutes, 1 seconds)

--- End code ---

I also made sure that I was able to link to regex (to rule out that I built boost badly).  I'm not getting errors for regex, and if completely remove all the thread stuff the project builds and runs fine.

I don't see anything wrong with how I've configured everything.  What gives?

herrtool:
I fixed it.  Nothing to do with Code::Blocks.  Sorry for the trouble!


--- Code: ---#include <iostream>
#define BOOST_THREAD_USE_LIB
#include <boost/regex.hpp>
#include <boost/thread.hpp>

int main(int argc, char** argv)
{
  boost::regex reg("^.*$");
  boost::thread t;
  system("PAUSE");
  return 0;
}

--- End code ---

That #define was not required with the version of boost I was using before.

Navigation

[0] Message Index

Go to full version