开发者

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'


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


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.


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

#include <boost\thread.hpp>


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...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜