服务器环境搭建
操作系统 :centos7
1. 可以看一下有没有boost软件包
yum list | grep boost
2. 有就直接安装,没有就去网上找
yum install boost
yum install boost-devel
yum install boost-doc
3. 编译这段test程序,成功则安装成功 (不会有人不会编译吧)
#include <iostream> #include <boost/timer.hpp> using namespace std; int main() { boost::timer t; cout << "max timespan:"<<t.elapsed_max()/3600<<"h"<<endl; cout << "min tmiespan:"<<t.elapsed_min()<<"s"<<endl; cout<<"now time elapsed:"<<t.elapsed()<<"s"<<endl; return 0; }
4. 安装yaml,(如果cmake版本过低,请看第5步 )
git clone https://github.com/jbeder/yaml-cpp.git cd yaml-cpp mkdir build cd build cmake .. make -j 4 sudo make install
5. 升级cmake
## 1. 查看当前cmake版本 [root@localhost ~]# cmake -version cmake version 2.8.12.2 ## 2. 进行卸载 [root@localhost ~]# yum remove -y cmake ## 3. 进行安装包的下载,也可以下载好安装包后传至相应的目录 [root@localhost ~]# mkdir /opt/cmake [root@localhost ~]# cd /opt/cmake/ ## 4. 下载或拷贝,解压 [root@localhost cmake]# wget https://cmake.org/files/v3.16/cmake-3.16.6.tar.gz [root@localhost cmake]# tar -zxvf cmake-3.16.6.tar.gz ## 5. 安装基本工具 [root@localhost cmake]# yum install -y gcc gcc-c++ ## 6. 进行编译连接
[root@localhost cmake]# cd cmake-3.16.6 [root@localhost cmake]# ./configure --prefix=/usr/local/cmake ## 7. 安装 [root@localhost cmake-3.16.6]# make && make install ## 8. 创建链接 [root@localhost cmake-3.16.6]# ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake ## 9. 查看版本 [root@localhost cmake-3.16.6]# cmake -version cmake version 3.16.6 CMake suite maintained and supported by Kitware (kitware.com/cmake). [root@localhost cmake-3.16.6]# [root@localhost cmake-3.16.6]#
6. 测试Yaml,写一个config.yaml配置文件
lastLogin: 2020-09-18 10:17:40
username: root
password: 123
7. c++代码,源文件名demo1.cpp
#include <yaml-cpp/yaml.h> #include <iostream> #include <string> #include <fstream> using std::cout; using std::endl; int main(int argc, char* argv[]) { YAML::Node config = YAML::LoadFile("config.yaml"); if (config["lastLogin"]) { std::cout << "Last logged in: " << config["lastLogin"].as<std::string>() << std::endl; } const std::string username = config["username"].as<std::string>(); const std::string password = config["password"].as<std::string>(); config["lastLogin"] = "2020-09-19 11:17:40"; std::ofstream fout("config.yaml"); fout << config; return 0; }
8. 编译 运行,编译后能运行则安装成功。
g++ demo1.cpp -o demo1 -std=c++11 -I/usr/local/include -L/usr/local/lib64 -lyaml-cpp
./dome1
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号