OS:OracleLinux 5.9 64bit
cpprest需要安装以下模块: 1 g++4.8以上,这里使用g++5.4.0 2 boost1.5.4以上,这里使用boost1.6.4 3 openssl1.0.0以上,这里使用openssl1.0.2-stable 4 camek3.0.0以上,这里使用cmake3.7.2
/path/to/install是安装前缀,库相关文件会安装在/path/to/install/lib或/path/to/install/lib64中,头文件在/path/to/install/include,以此类推。一般设置为/usr/local(也是默认值)
一个一个来安装 Step 1: g++5.4.0 1.1 下载官网 http://ftp.gnu.org/gnu/gcc/ 找到需要的版本 1.2 g++有三个前置要求:gmp、mpfr和mpc,这三个都可以在ftp://gcc.gnu.org/pub/gcc/infrastructure/ 找到,也可以到它们各自的官网上下到最新版,它们的安装方法很简答就是利用压缩包里的configure,依赖关系为:gmp无依赖关系,mpfr依赖gmp,mpc依赖gmp和mpfr 下面以安装mpfr为例: ./configure –prefix=/path/to/install/ –with-gmp=/path/to/gmp && make && make install 1.3 安装完之后就可以安装g++了: ./configure –prefix=/path/to/install/ –with-gmp=/path/to/gmp –with-mpfr=/path/to/mpfr –with-mpc=/path/to/mpc –disable-multilib 最后一个选项是只生成64位的库(应该是跟当前系统有关)
Step 2:boost 2.1 找到boostorg的git仓库https://github.com/boostorg/boost 2.2 git clone –recursive -b boost-1.6.4 https://github.com/boostorg/boost.git 2.3 进入boost目录,运行bootstrap.sh配置toolset等 2.4 运行./b2编译boost库,其中有很多可选参数,可以自行参考 注意的是这里可能会漏掉关键库zlib,这个自己用前面的方法configure安装即可;如果需要用到python还需要安装python-devel;这一步会将源码编译到boost,库编译到stage/lib中 2.5 ./b2 install –prefix=/path/to/install 把库安装到对应对应路径中 到这里boost安装结束
Step 3:openssl 3.1 找到openssl的git仓库https://github.com/openssl/openssl 3.2 git clone -b OPENSSL-1.0.2-stable https://github.com/openssl/openssl.git 3.3 进入目录./configure –prefix=/path/to/install配置编译安装静态库 3.4 make && make install 3.5 ./configure shared –prefix=/path/to/install配置编译安装动态库 3.6 make && make install
Step 4:cmake 方式同样走configure -> make -> make install的步骤不多说了
Step 5:cpprestsdk 这里太多坑啦 5.1 找到官方git仓库https://github.com/Microsoft/cpprestsdk 5.2 git clone https://github.com/Microsoft/cpprestsdk 5.3 进入Release目录,创建build目录并进入 5.4 cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=/path/to/gcc -DCMAKE_CPLUS_COMPILER=/path/to/g++ -DCMAKE_INSTALL_PREFIX=/path/to/install 可能会找不到boost_random,可以通过复制boost源文件的libs/random/include/boost/random.hpp到/path/to/install/include/boost中,这里为什么出错的原因搞不明白,不知是不是boost的问题 5.5 make&&make install 这一过程同样可能找不到头文件,可以参照5.4的方法拷贝头文件到对应位置 除此之外,还有可能出现诸如dlopen/dlclose找不到的情况,举个例子 [ 97%] Building CXX object samples/Oauth1Client/CMakeFiles/oauth1client.dir/stdafx.cpp.o [ 98%] Linking CXX executable ../../Binaries/oauth1client ../../Binaries/libcpprest.so.2.9: undefined reference to dladdr' ../../Binaries/libcpprest.so.2.9: undefined reference todlopen’ ../../Binaries/libcpprest.so.2.9: undefined reference to dlclose' ../../Binaries/libcpprest.so.2.9: undefined reference todlerror’ ../../Binaries/libcpprest.so.2.9: undefined reference to `dlsym’ 这里打开samples/Oauth1Client/CMakeFiles/oauth1client.dir/link.txt 在最后加上-ldl编译选项,就可以解决
—-以下可以无视 交叉编译相关 交叉编译器:arm-linux-gnueabihf-g++
openssl 1 ./config no-asm shared –prefix=/usr/arm-linux-gnueabihf 2 修改Makefile CC=arm-linux-gnueabihf 删掉所有-m64选项 3 make && make install
boost 1 该库使用的是bjam编译,因此需要修改project-
cpprest 1 该库使用的是使用toolChain.cmake —-以上可以无视