起语
版权声明:
https://blog.csdn.net/mlyjqx/article/details/74783811
Linux 安装Boost
(建议买一个某云/某腾服务器, 又便宜有又快, 不需要虚拟机这么麻烦!)
Boost库是为C++语言标准库提供扩展的一些C++程序库的总称,由Boost社区组织开发、维护。Boost库可以与C++标准库完美共同工作,并且为其提供扩展功能。今天就介绍一下Linux的安装
一、安装方法
安装boost的时候,其实很简单,按如下步骤安装:
wget http://sourceforge.net/projects/boost/files/boost/1.54.0/boost_1_54_0.tar.gz
tar -xzvf boost_1_54_0.tar.gz
cd boost_1_54_0
./bootstrap.sh --prefix=/usr/local
./b2 install --with=all
boost库被安装在/usr/local/lib下面
二、编译错误
若编译带有boost库的应用程序时,如在终端
运行命令:
g++ syslogem.cpp -lboost_system
若出现如下错误
undefined reference to
boost::system::generic_category()' undefined reference to
boost::system::generic_category()’
undefined reference to `boost::system::system_category()’
只好添加路径
g++ syslogem.cpp -L/usr/local/lib -lboost_system
三、运行错误
若再运行阶段出现如下错误
error while loading shared libraries: libboost_system.so.1.54.0: cannot open shared object file: No such file or directory
在可以进行如下解决:
1)添加环境变量:LD_LIBRARY_PATH=/usr/local/lib
查看头文件
/usr/local/include/boost/…
如这次的示例: cat /usr/local/include/boost/lexical_cast.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <iostream> #include <string> #include <boost/lexical_cast.hpp> #define ERROR_LEXICAL_CAST 1 int main() { using boost::lexical_cast; int a = 0; double b = 0.0; std::string s = ""; int e = 0; try { // ----- 字符串 ---> 数值 a = lexical_cast<int>("123"); b = lexical_cast<double>("123.12"); // ----- 数值 --> 字符串 s = lexical_cast<std::string>("123456.7"); // ----- 异常处理演示 e = lexical_cast<int>("abc"); } catch (boost::bad_lexical_cast& e) { std::cout << e.what() << std::endl; return ERROR_LEXICAL_CAST; } std::cout << a << std::endl; std::cout << b << std::endl; std::cout << s << std::endl; std::cout << "Hello world" << std::endl; return 0; }
运行结果:
帮助文档:
http://zh.highscore.de/cpp/boost/frontpage.html
结语:
时间: 2020-10-09
最后
以上就是朴素奇迹最近收集整理的关于Linux 安装boost | 使用的方法的全部内容,更多相关Linux内容请搜索靠谱客的其他文章。
发表评论 取消回复