Compile boost1.53 under Ubuntu


1. Download boost 1.53.0 from boost official website

2. Execute apt-get install build-essential (the purpose is to install some tools such as gcc, g++, etc. for compilation)
      Note: I am operating under the root user, and ordinary users execute sudo apt-get install build-essential 


3. Unzip the boost library to /usr/share/
      Copy the downloaded boost 1.53.0.tar.gz (I use this version) to the /usr/share/ directory, and then unzip it, a boost_1_53_0 will be automatically generated Folder (or use the command to decompress, I won’t mention it here, you can check the decompression command yourself)

4. Compile bjam (this stuff is used to compile the boost library).
      Before compiling, do the following operations. Since this version is compiled for msvc version of bjam, we change it to gcc version of bjam...
      Enter boost1 .53.0 Unzip the directory, find bootstrap.bat, open it with Notepad, and then modify:
      line 13, change call .\build.bat > ..\..\..\bjam.log to call .\build.bat gcc > . . In line 33 of \..\..\bjam.log,
     change set toolset=msvc to set toolset=gcc,
     save and exit, then double-click bootstrap.sh to execute it in the terminal, and after a while, bjam will be generated in boost_1_53_0

     Or generate bjam directly. Enter in the terminal

                      ./bootstrap.sh

5. Compile the boost library: Enter the /usr/share/boost_1_53_0 directory in the terminal,
     enter cd /usr/share/boost_1_53_10 in the terminal
     , and then enter ./bjam toolset=gcc --layout=tagged --build- under the root user type=complete stage to fully compile
     (execute for ordinary users: sudo ./bjam toolset=gcc --layout=tagged --build-type=complete stage )
      After a long wait, after the command is executed, all versions of the Library, and stored in:
         /usr/share/boost_1_53_0/stage
6. boost has been compiled, call the boost library below
    1. Generate a boost library include folder connection under /usr/include/:
       ln -s / usr/share/boos t_1_53_0/boost /usr/include/boost
    2. Generate all corresponding links of lib library files compiled by boost under /usr/lib/ Switch to the stage directory and execute
       find $PWD/lib/*. * -type f -exec ln -s {} /usr/lib/ \;
       (Ordinary user execution: sudo find $PWD/lib/*.* -type f -exec ln -s {} /usr/lib/ \; )


  There are two ways to add environment variables (you need to restart or logout to update the newly modified environment variables after the modification) :
  (1) Modify the end of the /etc/profie file and add
           export BOOST_INCLUDE=/usr/local/include/boost-1_52
           export BOOST_LIB=/usr/local/lib
   (2) Create a new shell file boost.sh in /etc/profile.d/
            #!/bin/sh 
            export BOOST_INCLUDE=/usr/local/include/boost-1_52
            export BOOST_LIB=/ usr/local/lib

test:
test.cpp

#include<boost/lexical_cast.hpp>
#include <iostream>
int main()
{ using boost::lexical_cast; int a =lexical_cast<int>("123"); double b =lexical_cast<double>("123.12"); std::cout<<a<<std::endl; std::cout<<b<<std::endl; return 0; }
       
       
       
       
       
       

After performing the above operations, it is ok



=================================【Reprint】============== ==============================
http://www.cppfun.com/2012/03/31/codeblocks-with- boost-under-linux.html

Set up a Code::Blocks global variable for Boost

global variable

global variable

This step only needs to be performed once, after whichthe globalvariable you’ve created will be available for anyproject.

  • Open the Settings menu and select “Global variables…”
  • Click the “New” button next to the Current variable list,specify a name like “boost”, and hit OK
  • In the “base” field of the Builtin fields section, browse forthe base of your Boost location — the path you specified in the–prefix option of the build command(*mandatory)
  • In the “include” field, browse for the header files location —the path can same with the “base” or like “/usr/local/include” or/usr/include.
  • In the “lib” field, browse for the “stage/lib” subfolder ofyour Boost installation — it should be the path in the “base” fieldwith “/stage/lib” tacked on. (This is the folder that containseither multiple lib*.aor *.lib files.)[maybe a path like "/usr/local/lib" or "/usr/lib"].
  • Hit the Close button to save your global variable

Add Boost search directories to your project

search directories - compiler

search directories - compiler

search directories - linker

search directories - linker

  • Right-click your project’s name in the Projects section of theManagement window and select “Build options…”
  • Highlight the root of your project in the tree on the left sideof the Project build options window
  • Select the “Search directories” tab
  • With the “Compiler” subtab selected, click the Add button,enter “$(#boost.include)” (without thequotes), and hit OK
  • With the “Linker” subtab selected, click the Add button, enter“$(#boost.lib)”(without the quotes), and hit OK

Include Boost headers and link with Boost libraries

Your project is now ready to use the Boost libraries. For eachlibrary you want to use, do the following:

  • #include<boost/*.hpp> in yoursource file
  • In your project’s build options, highlight the root of yourproject, select the “Linker settings” tab, and add“boost_*” to your Link libraries[or another way under"Other link options" something like "-lboost_system -lboost_thread-..."]

Add Other libraries into Code::Blocks

The same way like boost, just do as above steps, enjoy.


Guess you like

Origin blog.csdn.net/myemailsz/article/details/8770119