Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include boost::thread in your C++ project?

What do I need to do to include boost::thread in my project? I have copied the whole thread folder to my working path (I wish to be able to run this on several computers) and I get

fatal error C1083: Cannot open include file: 'boost/thread/detail/platform.hpp': No such file or directory

From the line #include "thread/thread.hpp"

What gives?

edit: Even if I just link to the boost folder where the precompiled binary installed and I use #include <boost/thread/thread.hpp> I get

fatal error LNK1104: cannot open file 'libboost_thread-vc90-mt-1_41.lib'

like image 711
Chris Avatar asked Feb 01 '10 03:02

Chris


2 Answers

Unfortunately boost::thread is not a "header-only" library -- hence you need to have it compiled. There are basically two ways to go around it.

  1. you download a prebuilt install package from boostpro (assuming that you are on windows) -- https://sourceforge.net/projects/boost/files/boost-binaries/
  2. you can build it yourself - see http://www.boost.org/doc/libs/1_35_0/more/getting_started/index.html
like image 97
Kornel Kisielewicz Avatar answered Sep 18 '22 10:09

Kornel Kisielewicz


Once you have downloaded, unzipped and installed the boost libraries in your Visual Studio environment, and told the Visual Studio project where the Boost libraries live, you are not quite finished yet. There exist a number of libraries in Boost libraries that require that you build them yourself. Boost threads is one such library.

  1. Build the bjam.exe program if you have not already done it. Probably the simplest way to is to get and run it direct from BoostPro, telling the installation which of the libraries (threads) you wish to install – you don't have to install all of them.

  2. Go to the C:\Program Files\boost_1_46_1\tools\build\v2\engine\src directory and run build.bat from the command prompt. Running the build.bat script will create bjam.exe inside this directory: C:\Program Files\boost_1_46_1\tools\build\v2\engine\src\bin.ntx86

  3. Select the bjam.exe into in your PATH environment variables. Include the directory C:\Program Files\boost_1_46_1\tools\build\v2\engine\src\bin.ntx86 as another environment variable.

  4. At the command prompt, go to the C:\Program Files\boost_1_46_1 directory, enter “bjam”, waiting for approximately 5-10 minutes while the program gets created.

  5. In your Visual Studio project select Configuration Properties -> Linker -> Input -> Additional Dependencies and enter libboost_thread-vc100-mt-gd-1_46_1.lib.

  6. In your Visual Studio project set the project configuration properties -> Linker -> General -> Additional Include Directories, telling it the location of the stage/lib folder eg C:\Program Files\Boost_1_46_1\stage\lib.

That should be sufficient to get you going. For more comprehensive details, please see this blog posting.

like image 38
AndyUK Avatar answered Sep 20 '22 10:09

AndyUK