axel静态编译 linux,33、静态编译boost源码,可提供Android的c++开发模块使用

基本思想:本来项目需求,需要写Android代码,开发组件模块,因为极其讨厌java;顾转而使用Android studio 提供了c++的功能,开发功能模块;之前的代码使用了boost库,所以需要使用boost源码静态编译成静态包,然后导入Android studio工程使用;

需要使用交叉编译器去编译liboost的的源码,我为了方便并未使用交叉编译器去编译https://blog.csdn.net/sxj731533730/article/details/106115331,以PC机为例子写了本教程;

{ 进入目录执行./bootstrap.sh;

此时形成bjam文件和project-config.jam 编辑project-config.jam, 仅修改using gcc这行。因为我使用的是arm-none-linux-gnueabi-g++,所以将其改以下即可: using gcc : arm  : arm-none-linux-gnueabi-g++; (注意空格和冒号)}

1、下载源代码

axel -n 100 https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.bz2

tar -jxvf boost_1_73_0.tar.bz2

cd boost_1_73_0/

mkdir liboost

./bootstrap.sh

./b2 -a cxxflags='-fPIC -std=c++11' install --prefix=/home/ubuntu/boost_1_73_0/liboost link=static threading=multi

然后在liboost文件夹产生了对应的头文件include和lib静态包

ubuntu@ubuntu:~/boost_1_73_0/liboost$ tree -L 2

.

├── include

│   └── boost

└── lib

├── cmake

├── libboost_atomic.a

├── libboost_chrono.a

├── libboost_container.a

├── libboost_context.a

├── libboost_contract.a

├── libboost_coroutine.a

├── libboost_date_time.a

├── libboost_exception.a

├── libboost_fiber.a

├── libboost_filesystem.a

├── libboost_graph.a

├── libboost_iostreams.a

├── libboost_locale.a

├── libboost_log.a

├── libboost_log_setup.a

├── libboost_math_c99.a

├── libboost_math_c99f.a

├── libboost_math_c99l.a

├── libboost_math_tr1.a

├── libboost_math_tr1f.a

├── libboost_math_tr1l.a

├── libboost_nowide.a

├── libboost_prg_exec_monitor.a

├── libboost_program_options.a

├── libboost_python27.a

├── libboost_random.a

├── libboost_regex.a

├── libboost_serialization.a

├── libboost_stacktrace_addr2line.a

├── libboost_stacktrace_backtrace.a

├── libboost_stacktrace_basic.a

├── libboost_stacktrace_noop.a

├── libboost_system.a

├── libboost_test_exec_monitor.a

├── libboost_thread.a

├── libboost_timer.a

├── libboost_type_erasure.a

├── libboost_unit_test_framework.a

├── libboost_wave.a

└── libboost_wserialization.a

4 directories, 40 files

然后就原则上可以把这个liboost文件夹导入Android Studio 的工程中使用静态库了;

测试代码:

#include #include using namespace std;

int main()

{

boost::gregorian::date d(boost::gregorian::day_clock::local_day());

cout << d.year()<

编译与执行:

ubuntu@ubuntu:~/test$ g++ -I liboost/include/ liboost/lib/libboost_timer.a testliboost.cpp

ubuntu@ubuntu:~/test$ ./a.out

2020.Aug.4

ubuntu@ubuntu:~/test$ g++ -I liboost/include/ -I liboost/lib/ testliboost.cpp

ubuntu@ubuntu:~/test$ ./a.out

2020.Aug.4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值