1. download the boost library from the offical website.

2. Unzip the file

    For windows, use 7zip for .7z file or use zip for .zip file.

    For ubuntu/linux/mac os x, use command: tar xjf boost_1_xx_x.tar.bz2 -f boost_1_xx_x  or tar zxf boost_1_xx_x.tar.gz -f boost_1_xx_x

3. Create the bjam/bj2, run the command by the script will create bjam and bj2. both two files are the same to build the libraries.

    For windows, run the "bootstrap.bat".

    For ubuntu/linux/max os x, run the "./bootstrap.sh",

4. Build the library.

    For visual studio, please use the command line tool provided by the vs. For example, for visual studio 2010,

    mkdir msvc

    ./bjam --toolset=msvc-10.0 --build-type=complete --with-filesystem --stagedir=msvc --disable-filesystem2

    For mingw/cybwin on windows, please make sure the compile binaries for mingw, gcc, could be foudn in command line. that means the environment variables contains the path for mingw.

    mkdir mingw

   ./bjam --toolset=gcc --build-type=complete --with-filesystem --stagedir=mingw --disable-filesystem2

   For ubunt/linux/mac os x's gcc, you should use the layout flag to named the libraries with version of boost.

   mkdir gcc

   ./bjam --toolset=gcc --build-type=complete --with-filesystem --stagedir=gcc --disable-filesystem2 --layout=versioned

   For mac os x's darwin

   ./bjam --toolset=darwin --build-type=complete --with-filesystem --stagedir=darwin --disable-filesystem2

Note:

   ./bjam --help

   ./bjam --show-libraries

5. Compile and link

    Create a file to use the file system or other libraries.

    include the boost/filesystem.hpp

    There are two main ways to link to libraries:

  1. You can specify the full path to each library:

    g++ main.cpp -o main -I/home/rogerluo/boost_1_49_0/ /home/user/boost_1_49_0/gcc/lib/libboost_filesystem.so /home/user/boost_1_49_0/gcc/lib/libboost_system.so
    
  2. You can separately specify a directory to search (with -Ldirectory) and a library name to search for (with-llibrary, dropping the filename's leadinglib and trailingsuffix (.a in this case):

    g++ main.cpp -o main -I/home/user/boost_1_49_0/ -L/home/rogerluo/boost_1_49_0/gcc/lib -lboost_system -lboost_filesystem
    

    both these two ways are to dynamically link to libraries, if you want to link statically the libraries,  for linking directly the files,

             g++ main.cpp -o main -I/home/rogerluo/boost_1_49_0/ /home/user/boost_1_49_0/gcc/lib/libboost_filesystem.a /home/user/boost_1_49_0/gcc/lib/libboost_system.a 

     on ubuntu/linix system, (.so) is dynamic library, (.a) is static library.

     For linking the file statically in the second way, declare the -static to make the linker to know using statically linking.

             g++ main.cpp -o main -I/home/user/boost_1_49_0/ -L/home/user/boost_1_49_0/gcc/lib -lboost_system -lboost_filesystem -static

Note:

Using the second way to link libraries,

For visual studio on window, change the linker setting: Additional library directories: $(BOOST_DIR)\msvc\lib\

For mingw on windows(using codeblock), settings->compiler and debuger, choose a compiler and under the "Linkder settings" add "libboost_system-mgw47-1_49" and "libboost_filesystem-mgw47-1_49", if you want to statically link to library, input "-static" into the "Link options".


make sure the LD_LIBRARY_PATH can contain path of boost library, modify the .profile under the your home directory, put this script at the end of the file.

export LD_LIBRARY_PATH=/home/user/boost_1_49_0/gcc/lib:$LD_LIBRARY_PATH




    

   



相关文章:

  • 2021-09-10
  • 2021-10-02
  • 2022-03-05
  • 2022-12-23
  • 2021-07-11
  • 2021-12-17
  • 2022-02-28
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-22
相关资源
相似解决方案