zoukankan      html  css  js  c++  java
  • boost library usage

    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
    




        

       



  • 相关阅读:
    龙果支付系统
    Java并发多线程
    StringRedisTemplate常用操作
    统一支付平台转型
    IntValue()方法 和 ValueOf()方法
    Java中一些知识的归纳总结
    mybatis的一些特殊符号标识(大于,小于,等于,不等于)
    MySQL中大于等于小于等于的写法
    boost::bind应用示例
    VC除零异常(错误)捕获
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/2846718.html
Copyright © 2011-2022 走看看