美文网首页
Mac安装boost

Mac安装boost

作者: 克里斯加德纳 | 来源:发表于2018-01-22 16:08 被阅读0次

    boost安装

    1.boost安装包下载
    https://sourceforge.net/projects/boost/files/boost/1.62.0/

    2.解压并进入boost_1_62_0文件夹

    3.执行boostrap.sh

    ./boostrap.sh
    

    4.上一步执行成功后会生成b2脚本,执行它

    ./b2
    

    执行完毕后,头文件在boost_1_62_0/boost文件夹下
    库文件在boost_1_62_0/stage/lib文件夹下
    或者执行

    ./b2 install 
    

    执行完毕后头文件在/usr/local/include下
    库文件在/usr/local/lib下

    到这里安装结束

    测试

    直接包含一个头文件编译看是否通过即可

    #include <boost/asio.hpp>
    int main()
    {
    }
    

    g++使用第三方库编译是如下命令

    g++ a.cpp  -I 头文件路径 -L 库文件路径 -l 动态链接库
    

    对应到我们这里应该是

     g++ a.cpp  -I /usr/local/include -L /usr/local/lib -l boost_system -l boost_thread
    

    必须要加,-l boost_system -l boost_thread,否则会报错

      Undefined symbols for architecture x86_64:
    “boost::system::system_category()”, referenced from: 
    boost::asio::error::get_system_category() in a-0e6774.o 
    ___cxx_global_var_init.2 in a-0e6774.o 
    “boost::system::generic_category()”, referenced from: 
    ___cxx_global_var_init in a-0e6774.o 
    ___cxx_global_var_init.1 in a-0e6774.o 
    ld: symbol(s) not found for architecture x86_64 
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    XCode上使用

    1.点击【项目工程文件】-》【Targets】-》【BuildSetting】-》【Search Paths】-》【Header Search Paths】输入头文件路径
    2.点击【项目工程文件】-》【Targets】-》【BuildSetting】-》【Search Paths】-》【Library Search Paths】输入库文件路径
    3.点击【项目工程文件】-》【Targets】-》【BuildSetting】-》【Linking】-》【Other Linker Flags】输入链接选项,输入-l boost_system -l boost_thread

    大功告成!

    相关文章

      网友评论

          本文标题:Mac安装boost

          本文链接:https://www.haomeiwen.com/subject/iznlaxtx.html