如何移植boost库到Android

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何移植boost库到Android相关的知识,希望对你有一定的参考价值。

  这里是使用NDK进行编译boost的但肯定对我有用吧。。经过一番折腾终于编译成功,,高兴,呵呵! 转载

  下面将主要的过程记录下来:

  1、下载boost 源码:

  Boost for android

  Boost for android is a set of tools to compile the main part of the Boost C++ Libraries for the Android platform.

  Currently supported boost versions are 1.45.0, 1.48.0 and 1.49.0.

  因此下载最新的 1.49 版本,下载完成后进行打补丁

  2、下载补丁代码

  boost-1_49_0

  3、打补丁代码

  boost_1_49_0.tar.bz2 放在android的 external 下解压:

  tar -xjvf external/boost_1_49_0.tar.bz2

  将boost-1_49_0.patch放在external\\boost_1_49_0下面根目录执行:

  patch -Np1 -d external/boost_1_49_0 < external/boost_1_49_0/boost-1_49_0.patch

  4、编写boost的makefile文件,即Android.mk

  LOCAL_PATH:= $(call my-dir)

  common_SRC_FILES := \\
  libs/thread/src/pthread/thread.cpp \\
  libs/thread/src/pthread/once.cpp \\

  common_SRC_FILES += \\
  libs/filesystem/v3/src/codecvt_error_category.cpp \\
  libs/filesystem/v3/src/operations.cpp \\
  libs/filesystem/v3/src/path.cpp \\
  libs/filesystem/v3/src/path_traits.cpp \\
  libs/filesystem/v3/src/portability.cpp \\
  libs/filesystem/v3/src/utf8_codecvt_facet.cpp \\
  libs/system/src/error_code.cpp \\
  libs/system/src/local_free_on_destruction \\

  include $(CLEAR_VARS)
  LOCAL_MODULE:= libboost
  LOCAL_SRC_FILES := $(common_SRC_FILES)

  prebuilt_stdcxx_PATH := prebuilts/ndk/current/sources/cxx-stl/gnu-libstdc++

  LOCAL_C_INCLUDES := \\
  $(LOCAL_PATH)/boost \\
  $(prebuilt_stdcxx_PATH)/include \\
  $(prebuilt_stdcxx_PATH)/libs/$(TARGET_CPU_ABI)/include/ \\

  LOCAL_C_INCLUDES += \\
  $(prebuilt_stdcxx_PATH)/include \\
  $(prebuilt_stdcxx_PATH)/libs/$(TARGET_CPU_ABI)/include/ \\
  $(prebuilt_supccxx_PATH)/include

  LOCAL_CFLAGS += -fvisibility=hidden -lpthread
  LOCAL_CPPFLAGS += -fexceptions -frtti

  LOCAL_SHARED_LIBRARIES := libc libstdc++ libstlport

  LOCAL_LDFLAGS += -L$(prebuilt_stdcxx_PATH)/libs/$(TARGET_CPU_ABI) -lgnustl_static -lsupc++

  LOCAL_MODULE_TAGS := optional
  include $(BUILD_SHARED_LIBRARY)
  比较重要的是上面 红色 部分文字

  最后编译生成:

  target thumb C++: libboost <= external/boost_1_49_0/libs/thread/src/pthread/thread.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/thread/src/pthread/once.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/codecvt_error_category.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/operations.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/path.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/path_traits.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/portability.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/utf8_codecvt_facet.cpp
  target thumb C++: libboost <= external/boost_1_49_0/libs/system/src/error_code.cpp
  target SharedLib: libboost (out/target/product/godbox/obj/SHARED_LIBRARIES/libboost_intermediates/LINKED/libboost.so)
  target Symbolic: libboost (out/target/product/godbox/symbols/system/lib/libboost.so)
  target Strip: libboost (out/target/product/godbox/obj/lib/libboost.so)
  Install: out/target/product/godbox/system/lib/libboost.so

  成功生成 libboost.so 库
参考技术A  这里是使用NDK进行编译boost的但肯定对我有用吧。。经过一番折腾终于编译成功,,高兴,呵呵! 转载

  下面将主要的过程记录下来:

  1、下载boost 源码:

  Boost for Android

  Boost for android is a set of tools to compile the main part of the Boost C++ Libraries for the Android platform.

  Currently supported boost versions are 1.45.0, 1.48.0 and 1.49.0.

  因此下载最新的 1.49 版本,下载完成后进行打补丁

  2、下载补丁代码

  boost-1_49_0

  3、打补丁代码

  boost_1_49_0.tar.bz2 放在android的 external 下解压:

  tar -xjvf external/boost_1_49_0.tar.bz2

  将boost-1_49_0.patch放在external\boost_1_49_0下面根目录执行:

  patch -Np1 -d external/boost_1_49_0 < external/boost_1_49_0/boost-1_49_0.patch

  4、编写boost的makefile文件,即Android.mk

  LOCAL_PATH:= $(call my-dir)

  common_SRC_FILES := \
  libs/thread/src/pthread/thread.cpp \
  libs/thread/src/pthread/once.cpp \

  common_SRC_FILES += \
  libs/filesystem/v3/src/codecvt_error_category.cpp \
  libs/filesystem/v3/src/operations.cpp \
  libs/filesystem/v3/src/path.cpp \
  libs/filesystem/v3/src/path_traits.cpp \
  libs/filesystem/v3/src/portability.cpp \
  libs/filesystem/v3/src/utf8_codecvt_facet.cpp \
  libs/system/src/error_code.cpp \
  libs/system/src/local_free_on_destruction \

  include $(CLEAR_VARS)
  LOCAL_MODULE:= libboost
  LOCAL_SRC_FILES := $(common_SRC_FILES)本回答被提问者采纳

移植命令和库到海思相关芯片

  • 编译fw_printenv工具: 

  •   make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- hi3521a_config

      make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux-

    make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- env

    编译会出现问题:只需进入u-boot目录

    vi include/linux/types.h +154

    //typedef u_int32_t                  uintmax_t;

    //typedef int32_t                    intmax_t;

    因为在arm-hisiv300-linux/target/usr/include/stdint.h 已经定已过了


    2.安装fw_printenv工具

    到/tools/env目录中,将编译好的fw_printenv拷贝到目标机的文件系统中,并通过"ln -s fw_printenv fw_setenv",创建一个fw_setenv到fw_printenv的软链。


    注意可以用:

    arm-hisiv300-linux-strip  fw_printenv  

    来去掉相应的符号来减少空间的浪费

    3.这个工具还需要一个配置文件,以获取uboot的ENV区域的位置信息。默认状态下,请将fw_env.config文件拷贝到目标机的文件系统的/etc目录下。然后结合uboot配置中定义的ENV区和Linux下mtd分区的情况修改配置文件。具体的修改方法见fw_env.config文件中的说明及/tools/env/README文件。



    移植ppp相关:

    1: 配置编译内核

    在内核原代码主目录下make menuconfig内核加入了ppp,socket 等选项

     

    Device Drivers -> Network device support  -> <*> PPP (point-to-point protocol)中,选中所有ppp选项:

    Device Drivers ->

        Network Device Support->

           <*> PPP (point-to-point protocol) support

           [*]   PPP multilink support

           <*> PPP support for async serial ports

           <*> PPP support for sync tty ports

           <*> SLIP (serial line) support

           [*]   CSLIP compressed headers

    Device Drivers -> Network device support -> <*> Universal TUN/TAP device driver support

    退出,保存配置,重新执行make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- uImage .

    将arch/arm/boot/下的uImage下载到开发板上重启系统。

     

    我的内核设置为:

    Device Drivers -> Network device support  -> <*> PPP (point-to-point protocol)中,选中所有ppp选项:

    Device Drivers ->

        Network Device Support->

           <M> PPP (point-to-point protocol) support

           [*]   PPP multilink support

           <M> PPP support for async serial ports

           <M> PPP support for sync tty ports

           <M> SLIP (serial line) support

           [*]   CSLIP compressed headers

    Device Drivers -> Network device support -> <M> Universal TUN/TAP device driver support

    需要将未安装的模块使用insmod命令加载.ko。  也可以直接向上面那样,编译出具有这些功能的内核(推荐)




    2、配置

    进入ppp/ppp-2.4.5/

    有两个目录etc.ppp scripts

    2.1 修改源代码scripts目录下的ppp-on ppp-on-dialer ppp-off

         之后复制到/etc/ppp目录下

         并修改执行权限,chmod +x ppp-on ppp-off ppp-on-dialer

    2.2 pppd提供认证信息时,可能协商使用PAP或者CHAP认证方式,所以需要修改源代码etc.ppp目录下的pap-secrets和chap-secrets,

     在pap-secrets添加需要的用户名和密码

     card * card * 

     在chap-secrets添加需要的用户名和口令

     card * card *


     之后将它们复制到/etc/ppp目录下


    相应的maefile如下:

    TOOLS_TOP_DIR ?= $(shell pwd)

    TOOL_TAR_BALL := ppp-2.4.5.tar.gz

    TOOL_NAME :=ppp-2.4.5

    TOOL_BIN := bin

    OSDRV_CROSS ?= arm-hisiv300-linux

    OSDRV_CROSS_CFLAGS ?= -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4

    subdir := pppd  pppdump  pppstats chat

    all:

    -rm $(TOOLS_TOP_DIR)/$(TOOL_NAME) -rf;

    tar -xvf $(TOOL_TAR_BALL);

    mkdir -p $(TOOLS_TOP_DIR)/$(TOOL_NAME)/$(TOOL_BIN)/;

    mkdir -p $(TOOLS_TOP_DIR)/$(TOOL_BIN)/;

    pushd $(TOOLS_TOP_DIR)/$(TOOL_NAME)/; \

    ./configure   > /dev/null; \

    make CC=arm-hisiv300-linux-gcc  -j 20 > /dev/null; \

    for d in $(subdir); do(arm-hisiv300-linux-strip $$d/$$d;cp $$d/$$d $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf); done 

    popd

    .PHONY: clean


    -pushd $(TOOLS_TOP_DIR)/$(TOOL_NAME)/ &&\

    make -C $(TOOLS_TOP_DIR)/$(TOOL_NAME)/ clean && \

    popd


    .PHONY: distclean

    distclean:

    -rm $(TOOLS_TOP_DIR)/$(TOOL_NAME) -rf;

    -rm $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf;


    iptables的配置:

    一、配置内核并编译,支持netfilter

    cd linux-3.10.y

    make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- menuconfig

    [*] Networking support  --->

           Networking options  --->

                  [*] Network packet filtering framework (Netfilter)  --->

                         Core Netfilter Configuration  --->(全部选上)

                         IP: Netfilter Configuration  ---> (全部选上)


    注意:这里的所有选项一定选为built-in [*],而不能选为Module [M],如果选为Module,重新烧制的系统内核里用modprobe ip_tables 命令将不能找到iptables模块。上一步还有一点要注意的是IP: Netfilter configuration中的FULL NAT选项一定要选中,否则将不能使用 iptables -t nat命令


    makefile修改入下:

    TOOLS_TOP_DIR ?= $(shell pwd)

    TOOL_TAR_BALL := iptables-1.6.1.tar.bz2

    TOOL_NAME :=iptables-1.6.1

    TOOL_BIN := install

    OSDRV_CROSS ?= arm-hisiv300-linux

    OSDRV_CROSS_CFLAGS ?= -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4

    all:

    -rm $(TOOLS_TOP_DIR)/$(TOOL_NAME) -rf;

    tar -xvf $(TOOL_TAR_BALL);

    mkdir -p $(TOOLS_TOP_DIR)/$(TOOL_BIN)/;

    pushd $(TOOLS_TOP_DIR)/$(TOOL_NAME)/; \

    ./configure  --host=$(OSDRV_CROSS) --prefix=$(TOOLS_TOP_DIR)/$(TOOL_BIN) \

      --enable-static --disable-shared  --disable-ipv6  --disable-nftables  \

    --disable-largefile > /dev/null; \

    make -j 20 > /dev/null; \

    make install  > /dev/null; \

    arm-hisiv300-linux-strip $(TOOLS_TOP_DIR)/$(TOOL_BIN)/sbin/xtables-multi

    rm -rf $(TOOLS_TOP_DIR)/$(TOOL_BIN)/sbin/iptables*

    mv $(TOOLS_TOP_DIR)/$(TOOL_BIN)/sbin/xtables-multi $(TOOLS_TOP_DIR)/$(TOOL_BIN)/sbin/iptables

    popd

    .PHONY: clean

    clean:

    -pushd $(TOOLS_TOP_DIR)/$(TOOL_NAME)/ &&\

    make -C $(TOOLS_TOP_DIR)/$(TOOL_NAME)/ clean && \

    popd

     

    .PHONY: distclean

    distclean:

    -rm $(TOOLS_TOP_DIR)/$(TOOL_NAME) -rf;

    -rm $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf;

     

    移植e2fsprogs相关

    TOOLS_TOP_DIR ?= $(shell pwd)

    TOOL_TAR_BALL := e2fsprogs-1.41.11.tar.gz

    TOOL_NAME := e2fsprogs-1.41.11

    TOOL_BIN := bin

    OSDRV_CROSS ?= arm-hisiv300-linux

    OSDRV_CROSS_CFLAGS ?= -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4

     

    all:

    -rm $(TOOLS_TOP_DIR)/$(TOOL_NAME) -rf;

    tar -xzf $(TOOL_TAR_BALL);

    mkdir -p $(TOOLS_TOP_DIR)/$(TOOL_NAME)/$(TOOL_BIN)/;

    mkdir -p $(TOOLS_TOP_DIR)/$(TOOL_BIN)/;

    pushd $(TOOLS_TOP_DIR)/$(TOOL_NAME)/; \

    ./configure --host=$(OSDRV_CROSS) CFLAGS="$(OSDRV_CROSS_CFLAGS)" \

    LDFLAGS="$(OSDRV_CROSS_CFLAGS)" --prefix=$(TOOLS_TOP_DIR)/$(TOOL_NAME)/$(TOOL_BIN) \

    --disable-tls > /dev/null; \

    make -j 20 > /dev/null; \

    make install  > /dev/null; \

    cp $(TOOL_BIN)/sbin/mkfs.ext2 $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf; \

    cp $(TOOL_BIN)/sbin/mkfs.ext3 $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf; \

    cp $(TOOL_BIN)/sbin/mkfs.ext4 $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf; \

    cp $(TOOL_BIN)/sbin/mke2fs $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf; \

    popd

    .PHONY: clean

     

    -pushd $(TOOLS_TOP_DIR)/$(TOOL_NAME)/ &&\

    make -C $(TOOLS_TOP_DIR)/$(TOOL_NAME)/ clean && \

    popd

     

    .PHONY: distclean

    distclean:

    -rm $(TOOLS_TOP_DIR)/$(TOOL_NAME) -rf;

    -rm $(TOOLS_TOP_DIR)/$(TOOL_BIN) -rf;

     顶层makefile如下:

    subdir:=ppp iptables e2fsprogs udev  reg-tools bftpd

    TOP_DIR:=$(shell pwd)

    TOP_BIN:=bin

    TOP_ETC:=etc

    all:

    mkdir -p $(TOP_DIR)/$(TOP_BIN) 

    mkdir -p $(TOP_DIR)/$(TOP_ETC) 

    for d in $(subdir); do (make -C $$d); done 

    cp creat_softlink.sh $(TOP_DIR)/$(TOP_BIN) && chmod a+x $(TOP_DIR)/$(TOP_BIN)/creat_softlink.sh

    for d in $(subdir); do (cp $$d/$(TOP_BIN)/* $(TOP_DIR)/$(TOP_BIN) -rf); done 

    for d in $(subdir); do (cp $$d/$(TOP_ETC)/* $(TOP_DIR)/$(TOP_ETC) -rf); done 

    .PHONY:clean distclean

    clean:

    for d in $(subdir); do (make clean -C $$d); done 

    distclean:

    -rm $(shell pwd)/bin -rf;

    -rm $(shell pwd)/etc -rf;

    for d in $(subdir); do (make distclean -C $$d); done 


    以上是关于如何移植boost库到Android的主要内容,如果未能解决你的问题,请参考以下文章

    如何在 pkg-config 中使用 C++ Boost 库?

    移植Eigen库到SylixOS下及使用方法

    linux下编译安装boost库

    linux下编译安装boost库

    Visual Studio 2019安装boost 1.7.0库

    Visual Studio 2019安装boost 1.7.0库