how to install boost correctly - c++

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:
extract boost_1_61_0 for example to C: so new folder named "C:\boost_1_61_0"
from a command prompt or visual studio 2015-> Visual studio tools-> developer command prompt for ms2015 (run it as administrator)
cd C:\boost_1_61_0
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:
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.

Related

Building boost with ICU support on Linux

boost build produces libboost-locale and libboost-regex so-files (elf) with RUNPATH=absolute/path/to/icu/build/bin
But I need to make my app portable with both boost and ICU so-files to be in the lib sub-directory inside my app distribution.
I am building boost with following commands:
./bootstrap.sh --prefix=absolute/path/to/myapp/build --with-icu=absolute/path/to/icu/build
./b2 install --with-locale --with-regex link=static,shared runtime-link=shared address-model=64 -sICU_PATH=absolute/path/to/icu/build
So it makes RUNPATHs=absolute/path/to/icu/build/bin (so also adds 'bin' to the passed ICU path).
When I add hardcode-dll-paths=true dll-path=".:../lib" to b2 command, it supplements RUNPATHs with ".:../lib", but absolute path to ICU-build is still there.

boost build finish with missing some files

my environment is next:
windows 7 ultimate x64
visual studio 2010 ultimate sp1
and using boost 1.55.0
get boost from boost.org (.zip) and follow next step to install
in administrator command :
c:\boost_download_folder>booststarp.bat
...
c:\boost_download_folder>b2 toolset=msvc-10.0 variant=debug,release link=static threading=multi address-model=32 runtime-link=static
...
c:\boost_download_folder>b2 toolset=msvc-10.0 variant=debug,release link=shared threading=multi address-model=32 runtime-link=shared
and it makes about 3g of files.
and i copied it to my project and include.
linker->general->Additional library directories : $(SolutionDir)\boost_1_55_0\lib;$(SolutionDir)\boost_1_55_0\stage\lib;
c/c++->additional include directories : $(SolutionDir)\boost_1_55_0
everything succeess and header file finding is fine.
but only error happen it is
LINK : fatal error LNK1104: 'libboost_system-vc100-mt-gd-1_55.lib'
i find deep and deep and finally i found it. the builded library folder has no libboost_system-vc100-mt-gd-1_55.lib file. i searched this file in Explorer but no libboost_system-vc100-mt-gd-1_55.lib is included in boost_1_55_0 folder.
but the next file is exist :
bin.v2\libs\system\build\msvc-10.0\release\address-model-32\link-static\runtime-link-static\threading-multi\libboost_system-vc100-mt-s-1_55.lib
stage\lib\libboost_system-vc100-mt-s-1_55.lib
bin.v2\libs\system\build\msvc-10.0\release\address-model-32\link-static\runtime-link-static\threading-multi\libboost_system-vc100-mt-s-1_55.lib.rsp
bin.v2\libs\system\build\msvc-10.0\debug\address-model-32\link-static\runtime-link-static-threading-multi\libboost_system-vc100-mt-sgd-1_55.lib
stage\lib\libboost_system-vc100-mt-sgd-1_55.lib
bin.v2\libs\system\build\msvc-10.0\debug\address-model-32\link-static\runtime-link-static-threading-multi\libboost_system-vc100-mt-sgd-1_55.lib.rsp
i think it missed with build. what i missed?? please help me

How to build boost static libs?

This works, but doesn't build static versions of boost libraries (maybe i am wrong?)
bjam --toolset=gcc --prefix=C:\boost_1_49_0-mingw install
Trying to issue folloving command:
bjam --toolset=gcc --prefix=C:\boost_1_49_0-mingw --build-type=complete install
but it doesn't work.
You should be able to use the link=static option to let you compile the library into your binary without needing the dynamic lib:
sudo ./b2 link=static
Check your stage directory to make sure it goes in the right spot and then re-install to whatever system directory you include.

Boost on windows with codeblocks - error: undefined reference to boost

Tons of these errors are popping up whenever I try to use boost in windows with codeblocks. On linux it works fine.
Even though I did add the boost .lib files and the include path to the GCC compiler in codeblocks.
I first compiled using bootstrap.bat + b2.exe but apperently that's wrong. A user in another forum said he fixed it but when I try his method I get:
So to clarify; what I did was:
. Add "C:\Program Files (x86)\CodeBlocks\MinGW\bin" to PATH
. Run bootstrap.bat which makes bjam.exe
. Run cmd.exe, cd to boost folder, enter bjam --build-dir=C:\boost --build-type=complete gcc stage
But then I get that error.
Why does compiling/using C++ libraries on windows always net these kind of errors that take hours to solve, while on linux it's nearly always flawless -.-
Who knows how to fix this one?
The technique that I use is as follows:
Set up the PATH environmental variable to include the bin directory of your GCC installation.
Extract boost somewhere.
Open a comand prompt and cd into the root of boost (the folder named boost_x_xx_x which has boost, doc, libs etc... subdirectories).
To compile boost, run:
bootstrap.bat
b2 toolset=gcc variant=release link=static threading=multi install
This will install boost to C:\Boost. If you want to install it elsewhere use the --build-dir= option when running b2.

Building Boost for static linking (MinGW)

I'm building Boost (I'm using System and FileSystem) for MinGW using bjam:
bjam --toolset=gcc stage
And it builds fine, but I want to be able to statically link to it (I have to have a single file for the final product) so I tried:
bjam --link=static --toolset=gcc stage
But I get the same output. Any ideas?
edit second question in a row I've answered moments after posting :p guess I'll leave this up here for others though.
bjam --build-type=complete --toolset=gcc stage
Will build both dynamic and static for sure.
I think link is a property as opposed to an option for bjam. That means that there should be no -- before it.
This is my command line for building only static libraries (visual c++ though):
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
Mapping that to your original build command I would say it should look something like this:
bjam --toolset=gcc link=static stage
or perhaps:
bjam stage --toolset=gcc link=static
Try running
bjam --help
for more info on properties and options for bjam.
Just want note that with the newer boost (Feb 2011) you need to build bjam as well now.. for some reason the current downloadable bjam doesn't work cleanly.
So first:
cd ...\boost_1_45_0\tools\build\v2\engine\src
build.bat mingw
Youll need to add bjam to the PATH (from control panel, not just on the cmd prompt). Then
cd ...\boost_1_45_0\
bjam --build-type=complete --toolset=gcc stage
My setup is Vista, Boost 1.45, MinGW 4.5, and building from cmd.exe not msys.
http://code-slim-jim.blogspot.com/2011/02/boost-in-vista-using-mingw-and-cmdexe.html
I have not built this myself in MinGW but I believe your first build will output both dynamic and static libraries and the second only static ones, so if you did not clean the build directories in between builds it will probably look the same.
When you write "I have to have a single file..." do you mean you need a single library containing all boost libraries? If so, I suspect you may have to 'ar' them together yourself.
I use the following command line to build both the statically linked as well as the dynamically linked versions of boost:
bjam "-sBUILD=debug release <runtime-link>static/dynamic <threading>multi" stage
This is done with visual c++ on windows YMMV.