Libgo 使用静态连接编译 运行在比较老的linux机器上方法

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 版本上执行,部署方便。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容