1.libgo介绍
详解 https://github.com/yyzybb537/libgo
2.Boost静态编译
在编译的centos上安装安装c和c++的静态库
yum install glibc-static libstdc++-static -y下载boost_1_59_0
执行bootstrap.sh
先动态编译
./b2 --without-python && ./b2 --without-python install静态编译连接
./b2 --without-python runtime-link=static link=static安装boost静态路
./b2 --without-python runtime-link=static link=static install
3.静态编译libgo
- libgo所依赖的boost必须先按静态库方式编译然后再编译libgo
- 编译
$cmake .. -DENABLE_BOOST_CONTEXT=ON
$ mkdir build
$ cd build
$ cmake ..
$ sudo make install
4.使用libgo,编写c++程序
- 在cmake项目在CMakeLists.txt 添加静态连接参数
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -static -static-libgcc -static-libstdc++")
通过静态连接,编译出来的可执行文件,可以在比较老的centos 版本上执行,部署方便。