Window 平台下安装Boost

    xiaoxiao2023-03-24  3

    Window 平台下安装Boost

    Window 平台下安装Boost 下载运行脚本编译配置项目的参数 附加包含目录附加库目录 测试

    最近因为要用C++做后台,所以就弄了一个Boost库,在网上看了很多的安装教程。可是,这些老司机总是只把你带到终点,就不告许你怎么弄的,或是断断续续的,所以就像写一篇完整一点的安装教程。

    下载

    首先,可以在boost网站上,下载一个boost的windows版本的压缩包。链接地址为:http://www.boost.org/users/download/ 点击到download页面之后,选择.7z版本的。

    运行脚本

    我使用的是vs2013 x64本机工具命令提示,进行运行脚本。这个是在安装vs2013的时候附带的工具,如果找不到,可以去vs2013的安装路径找一下。

    直接敲上bootstrap.bat就会在根目录生成bjam.exe

    编译

    64位机的编译命令

    bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization --without-wave --without-test --without -program_options --without-serialization --without-signals --stagedir=".\bin\vc12_x64" link= static runtime-link=shared threading=multi debug release address-model=64

    其中出现路径的是我设的值,你们请随意。

    如果出现了bin,说明编译成功了。

    配置项目的参数

    右键项目,然后选中属性。

    附加包含目录

    附加库目录

    测试

    #include <boost/lexical_cast.hpp> #include <iostream> using namespace std; int main() { using boost::lexical_cast; int a = lexical_cast<int>("123"); double b = lexical_cast<double>("123.0123456789"); string s0 = lexical_cast<string>(a); string s1 = lexical_cast<string>(b); cout << "number: " << a << " " << b << endl; cout << "string: " << s0 << " " << s1 << endl; int c = 0; try{ c = lexical_cast<int>("abcd"); } catch (boost::bad_lexical_cast& e){ cout << e.what() << endl; } system("pause"); return 0; }

    输出:

    number: 123 123.012 string: 123 123.0123456789 bad lexical cast: source type value could not be interpreted as target 请按任意键继续. . .
    转载请注明原文地址: https://ju.6miu.com/read-1200258.html
    最新回复(0)