6

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'

Chris
  • 21,549
  • 25
  • 71
  • 99
  • Have you built the libraries? Boost.Thread is one of the few Boost libraries that is _not_ header-only. – James McNellis Feb 01 '10 at 03:34
  • You're sure? I have no clue, but looking through the thread folder, they're all .hpp.. – Chris Feb 01 '10 at 03:36
  • 1
    Yes, I am sure. Read the "Getting Started" guide: http://www.boost.org/doc/libs/1_41_0/more/getting_started/index.html – James McNellis Feb 01 '10 at 03:37
  • Are you sure platform.hpp is where you need it to be? Also, are you using precompiled boost libs? – DigitalZebra Feb 01 '10 at 03:45
  • I am using the precompiled boost libraries, although I'd like to include them as part of my project and have it possible to move this application onto a computer that doesn't have boost installed, to be honest.. – Chris Feb 01 '10 at 03:55

4 Answers4

12

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
Endery
  • 1,090
  • 17
  • 31
Kornel Kisielewicz
  • 55,802
  • 15
  • 111
  • 149
  • 1
    I downloaded the prebuilt installation package, but I'd like to include the boost::thread stuff within the compilation of my project (which I'm sure will make it larger, but I'd like to run it on many computers that may not have boost installed) – Chris Feb 01 '10 at 03:46
  • 1
    @Chris, there are statically linked distributions of the libs from boostpro... this means you just have to link to the library and it will be included in your compilation. This way, you don't need to try and build the boost library yourself (ofc, assuming you are on windows). – DigitalZebra Feb 01 '10 at 03:48
  • @Polaris I'm currently on Windows, but will be running this application on some linux machines as well (thus the choice of boost::thread) – Chris Feb 01 '10 at 03:51
  • @Chris, in that case you'll need to get friendly with Boost.Build :) – Kornel Kisielewicz Feb 01 '10 at 03:59
  • Depends on your linux distro. On Debian (and I expect most/all Debian derivatives), boost::thread is just a quick "aptitude install libboost-thread-dev" away. – timday Feb 01 '10 at 12:33
2

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.

AndyUK
  • 3,933
  • 7
  • 42
  • 44
1

I was getting compile time error for 'boost::thread'. But it is resolved when I included following header.

#include <boost\thread.hpp>
Pabitra Dash
  • 1,461
  • 2
  • 21
  • 28
-1

Fatal Error C1083 is a Visual C++ error. You should include the library folder from boost in your project. "C:\Program Files\boost\boost_1_41\lib" if you're using boostpro.

Also when you're downloading the thread library with boostpro, you need to check it in the list (you can also choose the compiler...).

anno
  • 5,970
  • 4
  • 28
  • 37