简体   繁体   中英

how to install boost correctly

I've downloaded boost_1_61_0 and unzipped it. I used bootstrap.bat generating b2.exe and bjam.exe and successfully built libraries in a folder named "stage" for both x64 and win32 .

After I have .lib and boost folders containing include files.

When I remove the root folder I can't build my program. Why am I unable to build the code?

I have used bs as:

b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64 install

It creates C:\\boost that contains libs and header files. But when I try to use this new folder in my project I get errors: couldn't find eg: boost/reg.hpp

Is there a correct way to install boost after building it?

I figured it out:

  1. extract boost_1_61_0 for example to C: so new folder named "C:\\boost_1_61_0"
  2. from a command prompt or visual studio 2015-> Visual studio tools-> developer command prompt for ms2015 (run it as administrator)
  3. cd C:\\boost_1_61_0
  4. bootstrap.bat

So new files are created: b2.exe and bjam.exe in the root folder. Now we build the x64 version of boost library:

  1. b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64
  • new folder "Stage" is created in root folder, inside this folder there's a folder named x64 inside which there's a folder "lib" (.lib files). the process takes some minutes (about 20 minutes)

  • when it's done a message tells you that boost_1_61_0 skips some targets, don't mind it's nothing because it belongs to other OSs

now we build the x86 version:

b2 -j8 toolset=msvc-14.0 address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32

  • wait until it's done. now we have the two versions x64 and win32 but the root folder is too much big about 5.3 gigabyte.

now we install these two libraries to "C:\\Boost" and then clean by removing the folder "C:\\boost_1_61_0":

b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=C:\\Boost\\x64 install

  • I add install and changes the name of folder from stage to "C:\\Boost\\X64" when it's done a new folder "C:\\Boost" is created it contains include folder and x64 folder which contains lib files.

now we install win32 version: b2 -j8 toolset=msvc-14.0 address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=C:\\Boost\\win32 install

  • when it's done remove a folder named lib inside: C:\\Boost\\
  • time to clean and free up memory:
  • remove the hole folder: C:\\Boost_1_61_0 because we don't need it again

** how to add boost to my project?:

open Msvc2015->create c++ console new project, when it's created go to Project-> "MyBoostProject's" properties->C/C++->General->Additional include directories->edit->new folder->C:\\Boost\\include->boost_1_61 add another folder with the path: C:\\Boost\\include->Boost_1_61_0->Boost

now the include files are ready.

** How to link?:

If my project is x86: go to: linker->General->Additional Library Directories->edit->Add new folder->C:\\Boost\\win32\\Lib

If my project is x64:

linker->Additional library directories->edit->add new folder->C:\\Boost\\x64\\Lib

I wish this post would be useful for anyone who was not able to install it.

The boost includes are in the folder you created called c:\\boost. So the path is c:\\boost\\boost as it looks you have found out.

But better yet is to use environment variables. You will find them under control panel > system > advanced >...

Set BOOST_ROOT to c:\\boost and BOOST_LIB to your stage path. I keep all the builds v100, v140 x86 and 64 bit in the same folder. Then in your projects you can set additional include directories to $(BOOST_ROOT) and lib directories to $(BOOST_LIB)

This gets you lots of advantages like when 6.62 comes out you can put it in c:\\boost_62 and change your environment variables then all your projects are using the new boost. You don't have to get stuck with c:\\boost. And if you share the project with someone else with a different path, it just works.

BOOST_ROOT looks pretty universal out there, I don't know about BOOST_LIB

Also, if you change an environment variable, you will have to close Visual Studio and reopen it to have the change take affect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM