Skip to main content
GameDev.net gamedev.net
🔒 Locked

Building boost::thread lib

Started by Mantear Aug 27, 2008 at 3:12 PM 10 replies 14.4k views
Original Post
Mantear
Mantear
Greetings, After searching google and gamedev, I'm still confused about this. I'm trying to build the boost::thread static library on my WinXP machine, using VS2008 Pro as my IDE/compiler. I want to build it manually without just downloading it because I'm going to have to build it on some other systems. I know Windows better so I figured I'd start there. So far I've downloaded boost 1.36, boost-build, and boost-jam. I ran the build.bat file under boost-jam and got the bjam.exe. But now I'm not sure what to do with it. I'm trying to slog through the documentation, but I'm still kinda stuck. Any help would be greatly appreciated.
nife87
nife87
First, thanks for notifying me of 1.36 :)
Second, this is not really an answer to your question, but I just build boost::thread (1.36) by creating a project in CodeBlocks and compiling it with GCC 3.4.5 from scratch (just added the necessary cpp files) in there without issues. So this is an option if you just want the library. But, of course, if someone actually knows the answer to your question, that might help you faster than my solution.
mvBarracuda
mvBarracuda
If you got just MSVC2008 installed and no other C++ compiler, boost should automatically detect it and use it for building.

This guide pretty much covers it:
http://www.boost.org/doc/libs/1_36_0/more/getting_started/windows.html#prepare-to-use-a-boost-library-binary

In case MSVC2008 is the only C++ compiler, you can ignore the "Identify your toolset step" and continue with the following step. Good luck and let me know if it worked :-)

-----PARPG - open source isometric 2d old school RPG still looking for interested contributors
donny dont
donny dont
Boost is a great library, but most of the time has horrible documentation. One thing that should make your life a hell of a lot easier is doing the following.

bjam --toolset=msvc --prefix="C:\Boost" install

After running within the C:\Boost directory will be the following subdirectories.
include - The boost header files are located here.
lib - All the library files will be located here.

From there either point Visual Studio to look for header and library files or copy them to them to somewhere Visual Studio looks for them by default.

For my Vista PC with Visual Studio 2008 these locations are where the include and lib files are searched by default.

C:\Program Files\Microsoft SDKs\Windows\v5.0
C:\Program Files\Microsoft Visual Studio 9\VC
Then just copy the dlls to C:\Windows\system32

If you're planning on doing multiple projects using Boost its best to install the header and library files where the compiler expects them so you don't have to keep telling it where to look.

As a quick aside, you may want to look into the threadpool library . Its a header only library using boost thread to create a threadpool. Might be useful to you.
Mantear
Mantear
Everyone, thank you for your replies.

@ nife87: I was about to go down that path. Seems like a rather round-about method, but should work.

@ mvBarracuda: That's the documentation I was looking at. While it may provide enough information to someone who knows what they're doing, to someone new to boost and/or bjam, it's not nearly clear enough.

@ donny dont: Thanks a lot! Your suggestion worked. The only thing you left out is where I had to run that command from (the boost_x_xx_x directory). It looks like it's compiling everything right now.
Mantear
Mantear
Follow up question. When I try to compile a project using #include "boost/thread.hpp", it fails with a LINK error saying it can't find 'libboost_thread-vc90-mt-gd-1_36.lib'. I'm pointing my include paths to include C:\Boost\lib, and running bjam generated the 'libboost_thread-vc90-mt-1_36.lib' and 'libboost_thread-vc90-mt.lib' libraries, but not 'libboost_thread-vc90-mt-gd-1_36.lib'. What did I do wrong? Thanks.
Mantear
Mantear
/bump

After building Boost, I got two libs for the boost::thread class, 'libboost_thread-vc90-mt-1_36.lib' and 'libboost_thread-vc90-mt.lib'. However, when linking (using Visual Studio 2008 Pro), it says it cannot find 'libboost_thread-vc90-mt-gd-1_36.lib'. Did I do something wrong?
scottrick49
scottrick49
I had the same problem and it took me like an hour to figure out. You have to go into your project properties, c/c++ part, and then add additional include directories for any precompiled headers you are going to use. THEN (for your specific problem), go down to the linker part and you need to add to the Additional Library Directories. What was troubling me, was that you have to select the directory that each library is in - you can't just select c:\boost\libs or wherever you built them. You have to select the folder each .lib is in. What I did was just copied all the *.lib files in the whole directory structure and put them in one "super-lib" folder so I could just add one folder to VBs additional library directories thing.

ALSO, it looks like you may not have built the correct libraries. I dont remember what it was exactly, but there was an option that let me build ALL of the library types (debug, release, threading, etc). I just jumbled through the included documentation (the page about setting up on a windows system). You might want to just scan through that some more.
scottrick49
frat
frat
Hi,

when you
#include "boost/thread.hpp"

automatically the linker points to the correct version of the thread library, without the need to set anything in the IDE (this happens only with msvc, if you use another compiler, you have to set manually the paths and names).

You are compiling your app in debug mode, so boost is looking for the debug version of the library.
To compile the debug target with bjam, try this in the command line from the boost directory:

bjam --toolset=msvc --with-thread link=static stage

now go in the directory named "stage", and you will find both the version of the libraries, debug and release.
Mantear
Mantear
Hi frat,

I think you're on the right track, but I still didn't get quite what I needed. Using your command-line command, it regenerated 'libboost_thread-vc90-mt-1_36.lib' and 'libboost_thread-vc90-mt.lib', but still no 'libboost_thread-vc90-mt-gd-1_36.lib'

I see under the 'boost_x_xx_x\bin.v2\libs\thread\build\msvc-9.0\release\link-static\threading-multi' directory the 'libboost_thread-vc90-mt-1_36.lib' library. I'm assuming that's the library I want to link against when using a Release build. But I still don't see a debug version of the library being built anywhere. Any suggestions?
frat
frat

Please, check here:
boost_x_xx_x\bin.v2\libs\thread\build\msvc-9.0\debug\link-static\threading-multi
{notice that i substituded "release" with "debug" in the path)

by the way you can force the build of the debug target by typing
bjam --toolset=msvc --with-thread link=static debug
Mantear
Mantear
Ok, I think I finally got it. The final command-line command I used was:
bjam --toolset=msvc --build-type=complete --with-thread link=static stage

This:
Builds for the msvc toolsets
Builds every posibile library type (static, multi-threaded, debug, etc)
Builds only the 'thread' libraries
Builds for static linkage
Puts the final output to a 'stage' directory

There's no way I could have figured that out from the documentation alone... Thanks everyone!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.