当前位置: 首页 > 工具软件 > Boost > 使用案例 >

android平台移植boost库

尉迟国发
2023-12-01

android平台移植boost库

  • 在Android平台使用boost库,没有linux平台上那么方便。
    尤其在新版本ndk,高通的车机项目,网上的boost_for_android不一定适用。
    本人在移植安卓vsomeip时,采用以下方法 (部分boost库析构需要添加virtual)

步骤1: 克隆出boost

  • 不同于直接拉取整个boost仓库,这里采用拉取小仓库
$ mkdir boost-1.70.0
$ cd boost-1.70.0/
$ vi get_boost.sh 
git clone –branch boost-1.70.0 https://github.com/boostorg/accumulators.git
git clone –branch boost-1.70.0 https://github.com/boostorg/algorithm.git
git clone –branch boost-1.70.0 https://github.com/boostorg/align.git
git clone –branch boost-1.70.0 https://github.com/boostorg/any.git
git clone –branch boost-1.70.0 https://github.com/boostorg/array.git
git clone –branch boost-1.70.0 https://github.com/boostorg/asio.git
git clone –branch boost-1.70.0 https://github.com/boostorg/assert.git
git clone –branch boost-1.70.0 https://github.com/boostorg/assign.git
git clone –branch boost-1.70.0 https://github.com/boostorg/atomic.git
git clone –branch boost-1.70.0 https://github.com/boostorg/beast.git
git clone –branch boost-1.70.0 https://github.com/boostorg/bimap.git
git clone –branch boost-1.70.0 https://github.com/boostorg/bind.git
git clone –branch boost-1.70.0 https://github.com/boostorg/callable_traits.git
git clone –branch boost-1.70.0 https://github.com/boostorg/chrono.git
git clone –branch boost-1.70.0 https://github.com/boostorg/circular_buffer.git
git clone –branch boost-1.70.0 https://github.com/boostorg/compatibility.git
git clone –branch boost-1.70.0 https://github.com/boostorg/compute.git
git clone –branch boost-1.70.0 https://github.com/boostorg/concept_check.git
git clone –branch boost-1.70.0 https://github.com/boostorg/config.git
git clone –branch boost-1.70.0 https://github.com/boostorg/container.git
git clone –branch boost-1.70.0 https://github.com/boostorg/container_hash.git
git clone –branch boost-1.70.0 https://github.com/boostorg/context.git
git clone –branch boost-1.70.0 https://github.com/boostorg/conversion.git
git clone –branch boost-1.70.0 https://github.com/boostorg/convert.git
git clone –branch boost-1.70.0 https://github.com/boostorg/core.git
git clone –branch boost-1.70.0 https://github.com/boostorg/coroutine.git
git clone –branch boost-1.70.0 https://github.com/boostorg/coroutine2.git
git clone –branch boost-1.70.0 https://github.com/boostorg/crc.git
git clone –branch boost-1.70.0 https://github.com/boostorg/date_time.git
git clone –branch boost-1.70.0 https://github.com/boostorg/detail.git
git clone –branch boost-1.70.0 https://github.com/boostorg/disjoint_sets.git
git clone –branch boost-1.70.0 https://github.com/boostorg/dll.git
git clone –branch boost-1.70.0 https://github.com/boostorg/dynamic_bitset.git
git clone –branch boost-1.70.0 https://github.com/boostorg/endian.git
git clone –branch boost-1.70.0 https://github.com/boostorg/exception.git
git clone –branch boost-1.70.0 https://github.com/boostorg/fiber.git
git clone –branch boost-1.70.0 https://github.com/boostorg/filesystem.git
git clone –branch boost-1.70.0 https://github.com/boostorg/flyweight.git
git clone –branch boost-1.70.0 https://github.com/boostorg/foreach.git
git clone –branch boost-1.70.0 https://github.com/boostorg/format.git
git clone –branch boost-1.70.0 https://github.com/boostorg/function.git
git clone –branch boost-1.70.0 https://github.com/boostorg/functional.git
git clone –branch boost-1.70.0 https://github.com/boostorg/function_types.git
git clone –branch boost-1.70.0 https://github.com/boostorg/fusion.git
git clone –branch boost-1.70.0 https://github.com/boostorg/geometry.git
git clone –branch boost-1.70.0 https://github.com/boostorg/gil.git
git clone –branch boost-1.70.0 https://github.com/boostorg/graph.git
git clone –branch boost-1.70.0 https://github.com/boostorg/graph_parallel.git
git clone –branch boost-1.70.0 https://github.com/boostorg/hana.git
git clone –branch boost-1.70.0 https://github.com/boostorg/heap.git
git clone –branch boost-1.70.0 https://github.com/boostorg/icl.git
git clone –branch boost-1.70.0 https://github.com/boostorg/integer.git
git clone –branch boost-1.70.0 https://github.com/boostorg/interprocess.git
git clone –branch boost-1.70.0 https://github.com/boostorg/intrusive.git
git clone –branch boost-1.70.0 https://github.com/boostorg/io.git
git clone –branch boost-1.70.0 https://github.com/boostorg/iostreams.git
git clone –branch boost-1.70.0 https://github.com/boostorg/iterator.git
git clone –branch boost-1.70.0 https://github.com/boostorg/lambda.git
git clone –branch boost-1.70.0 https://github.com/boostorg/lexical_cast.git
git clone –branch boost-1.70.0 https://github.com/boostorg/locale.git
git clone –branch boost-1.70.0 https://github.com/boostorg/local_function.git
git clone –branch boost-1.70.0 https://github.com/boostorg/lockfree.git
git clone –branch boost-1.70.0 https://github.com/boostorg/log.git
git clone –branch boost-1.70.0 https://github.com/boostorg/logic.git
git clone –branch boost-1.70.0 https://github.com/boostorg/math.git
git clone –branch boost-1.70.0 https://github.com/boostorg/metaparse.git
git clone –branch boost-1.70.0 https://github.com/boostorg/move.git
git clone –branch boost-1.70.0 https://github.com/boostorg/mp11.git
git clone –branch boost-1.70.0 https://github.com/boostorg/mpi.git
git clone –branch boost-1.70.0 https://github.com/boostorg/mpl.git
git clone –branch boost-1.70.0 https://github.com/boostorg/msm.git
git clone –branch boost-1.70.0 https://github.com/boostorg/multi_array.git
git clone –branch boost-1.70.0 https://github.com/boostorg/multi_index.git
git clone –branch boost-1.70.0 https://github.com/boostorg/multiprecision.git
git clone –branch boost-1.70.0 https://github.com/boostorg/numeric_conversion.git
git clone –branch boost-1.70.0 https://github.com/boostorg/optional.git
git clone –branch boost-1.70.0 https://github.com/boostorg/parameter.git
git clone –branch boost-1.70.0 https://github.com/boostorg/phoenix.git
git clone –branch boost-1.70.0 https://github.com/boostorg/poly_collection.git
git clone –branch boost-1.70.0 https://github.com/boostorg/polygon.git
git clone –branch boost-1.70.0 https://github.com/boostorg/pool.git
git clone –branch boost-1.70.0 https://github.com/boostorg/predef.git
git clone –branch boost-1.70.0 https://github.com/boostorg/preprocessor.git
git clone –branch boost-1.70.0 https://github.com/boostorg/process.git
git clone –branch boost-1.70.0 https://github.com/boostorg/program_options.git
git clone –branch boost-1.70.0 https://github.com/boostorg/property_map.git
git clone –branch boost-1.70.0 https://github.com/boostorg/property_tree.git
git clone –branch boost-1.70.0 https://github.com/boostorg/proto.git
git clone –branch boost-1.70.0 https://github.com/boostorg/ptr_container.git
git clone –branch boost-1.70.0 https://github.com/boostorg/python.git
git clone –branch boost-1.70.0 https://github.com/boostorg/qvm.git
git clone –branch boost-1.70.0 https://github.com/boostorg/random.git
git clone –branch boost-1.70.0 https://github.com/boostorg/range.git
git clone –branch boost-1.70.0 https://github.com/boostorg/ratio.git
git clone –branch boost-1.70.0 https://github.com/boostorg/rational.git
git clone –branch boost-1.70.0 https://github.com/boostorg/regex.git
git clone –branch boost-1.70.0 https://github.com/boostorg/scope_exit.git
git clone –branch boost-1.70.0 https://github.com/boostorg/serialization.git
git clone –branch boost-1.70.0 https://github.com/boostorg/signals.git
git clone –branch boost-1.70.0 https://github.com/boostorg/signals2.git
git clone –branch boost-1.70.0 https://github.com/boostorg/smart_ptr.git
git clone –branch boost-1.70.0 https://github.com/boostorg/sort.git
git clone –branch boost-1.70.0 https://github.com/boostorg/spirit.git
git clone –branch boost-1.70.0 https://github.com/boostorg/stacktrace.git
git clone –branch boost-1.70.0 https://github.com/boostorg/statechart.git
git clone –branch boost-1.70.0 https://github.com/boostorg/static_assert.git
git clone –branch boost-1.70.0 https://github.com/boostorg/system.git
git clone –branch boost-1.70.0 https://github.com/boostorg/test.git
git clone –branch boost-1.70.0 https://github.com/boostorg/thread.git
git clone –branch boost-1.70.0 https://github.com/boostorg/throw_exception.git
git clone –branch boost-1.70.0 https://github.com/boostorg/timer.git
git clone –branch boost-1.70.0 https://github.com/boostorg/tokenizer.git
git clone –branch boost-1.70.0 https://github.com/boostorg/tti.git
git clone –branch boost-1.70.0 https://github.com/boostorg/tuple.git
git clone –branch boost-1.70.0 https://github.com/boostorg/type_erasure.git
git clone –branch boost-1.70.0 https://github.com/boostorg/type_index.git
git clone –branch boost-1.70.0 https://github.com/boostorg/typeof.git
git clone –branch boost-1.70.0 https://github.com/boostorg/type_traits.git
git clone –branch boost-1.70.0 https://github.com/boostorg/units.git
git clone –branch boost-1.70.0 https://github.com/boostorg/unordered.git
git clone –branch boost-1.70.0 https://github.com/boostorg/utility.git
git clone –branch boost-1.70.0 https://github.com/boostorg/uuid.git
git clone –branch boost-1.70.0 https://github.com/boostorg/variant.git
git clone –branch boost-1.70.0 https://github.com/boostorg/vmd.git
git clone –branch boost-1.70.0 https://github.com/boostorg/wave.git
git clone –branch boost-1.70.0 https://github.com/boostorg/winapi.git
git clone –branch boost-1.70.0 https://github.com/boostorg/xpressive.git
$ chmod +x get_boost.sh
$ ./get_boost.sh ~~(若脚本不行,可以考虑改进方法)~~ 

步骤2: 编写boost Android.bp

$ vi Android.bp
cc_defaults {
    name: “boost_defaults”,
    vendor: true,
//    vendor_available: true,
}
cc_defaults {
    name: “boost_headers_defaults”,
    defaults: [“boost_defaults”],
}
cc_defaults {
    name: “boost_library_defaults”,
    defaults: [“boost_defaults”],
    rtti: true,
    cflags: [
        “-Wall”,
//        “-Werror”,
        “-fexceptions”,
//        “-DBOOST_THREAD_DONT_USE_CHRONO”,
//        “-DBOOST_THREAD_POSIX”,
        “-DBOOST_ASIO_HAS_STD_STRING_VIEW”,
    ],
}
cc_library_headers {
    name: “libboost_headers”,
    defaults: [“boost_headers_defaults”],
    export_include_dirs: [
        “accumulators/include/”,
        “algorithm/include/”,
        “align/include/”,
        “any/include/”,
        “array/include”,
        “asio/include/”,
        “assert/include”,
        “assign/include”,
        “atomic/include”,
        “beast/include”,
        “bimap/include”,
        “bind/include/”,
        “callable_traits/include/”,
        “chrono/include”,
        “circular_buffer/include”,
        “compatibility/include”,
        “compute/include”,
        “concept_check/include”,
        “config/include”,
        “container/include”,
        “container_hash/include”,
        “context/include”,
        “conversion/include”,
        “convert/include”,
        “core/include”,
        “coroutine/include”,
        “coroutine2/include”,
        “crc/include”,
        “date_time/include”,
        “detail/include”,
        “disjoint_sets/include”,
        “dll/include”,
        “dynamic_bitset/include”,
        “endian/include”,
        “exception/include”,
        “fiber/include”,
        “filesystem/include”,
        “flyweight/include”,
        “foreach/include/”,
        “format/include/”,
        “function/include/”,
        “functional/include/”,
        “function_types/include/”,
        “fusion/include”,
        “geometry/include”,
        “gil/include”,
        “graph/include”,
        “graph_parallel/include”,
        “hana/include”,
        “heap/include”,
        “icl/include”,
        “integer/include”,
        “interprocess/include/”,
        “intrusive/include”,
        “io/include”,
        “iostreams/include”,
        “iterator/include”,
        “lambda/include”,
        “lexical_cast/include/”,
        “locale/include”,
        “local_function/include”,
        “lockfree/include”,
        “log/include”,
        “logic/include”,
        “math/include”,
        “metaparse/include”,
        “move/include”,
        “mp11/include”,
        “mpi/include”,
        “mpl/include”,
        “msm/include”,
        “multi_array/include”,
        “multi_index/include/”,
        “multiprecision/include/”,
//        “numeric/include”,
        “numeric_conversion/include”,
        “optional/include”,
        “parameter/include”,
        “phoenix/include”,
        “poly_collection/include”,
        “polygon/include”,
        “pool/include”,
        “predef/include”,
        “preprocessor/include”,
        “process/include”,
        “program_options/include”,
        “property_map/include”,
        “property_tree/include/”,
        “proto/include”,
        “ptr_container/include”,
        “python/include”,
        “qvm/include”,
        “random/include”,
        “range/include”,
        “ratio/include”,
        “rational/include”,
        “regex/include”,
        “scope_exit/include”,
        “serialization/include”,
//        “signals/include”,
        “signals2/include”,
        “smart_ptr/include”,
        “sort/include”,
        “spirit/include”,
        “stacktrace/include”,
        “statechart/include”,
        “static_assert/include”,
        “system/include”,
        “test/include”,
        “thread/include”,
        “throw_exception/include”,
        “timer/include”,
        “tokenizer/include/”,
        “tti/include/”,
        “tuple/include/”,
        “type_erasure/include”,
        “type_index/include”,
        “typeof/include/”,
        “type_traits/include”,
        “units/include”,
        “unordered/include”,
        “utility/include”,
        “uuid/include”,
        “variant/include/”,
        “vmd/include/”,
        “wave/include/”,
        “winapi/include/”,
        “xpressive/include/”,
    ]
}
cc_library {
    name: “libboost_chrono”,
    defaults: [“boost_library_defaults”],
    header_libs: [
        “libboost_headers”,
    ],
    shared: {
        shared_libs: [
            “libboost_system”,
        ],
    },
    srcs : [
        “chrono/src/**/*.cpp”,
    ],
    export_include_dirs: [“chrono/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_date_time”,
    defaults: [“boost_library_defaults”],
    header_libs: [
        “libboost_headers”,
    ],
    srcs : [
        “date_time/src/**/*.cpp”,
    ],
    export_include_dirs: [“date_time/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_filesystem”,
    defaults: [“boost_library_defaults”],
    //FIXME: build workaround
    cflags: [
        “-Wno-deprecated-declarations”,
        “-Wno-non-virtual-dtor”,
        “-Wno-unused-parameter”,
    ],
    header_libs: [
        “libboost_headers”,
    ],
    shared: {
        shared_libs: [
            “libboost_system”,
        ],
    },
    srcs : [
        “filesystem/src/**/*.cpp”,
    ],
    export_include_dirs: [“filesystem/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_log”,
    defaults: [“boost_library_defaults”],
    //FIXME: build workaround
    cflags: [
        “-Wno-implicit-fallthrough”,
        “-Wno-non-virtual-dtor”,
        “-Wno-unused-parameter”,
    ],
    header_libs: [
        “libboost_headers”,
    ],
    shared: {
        shared_libs: [
            “libboost_thread”,
            “libboost_filesystem”,
            “libboost_regex”,
            “libboost_system”,
        ],
    },
    srcs : [
        “log/src/**/*.cpp”,
    ],
    exclude_srcs : [
        “log/src/dump_ssse3.cpp”,
        “log/src/dump_avx2.cpp”,
        “log/src/windows/*.cpp”
    ],
    local_include_dirs : [
        “log/src”,
        “log/src/posix”,
        “log/src/setup”,
        “log/src/windows”,
    ],
    export_include_dirs: [“log/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_program_options”,
    defaults: [“boost_library_defaults”],
    header_libs: [
        “libboost_headers”,
    ],
    srcs : [
        “program_options/src/**/*.cpp”,
    ],
    export_include_dirs: [“program_options/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_regex”,
    defaults: [“boost_library_defaults”],
    //FIXME: build workaround
    cflags: [
        “-Wno-implicit-fallthrough”,
    ],
    header_libs: [
        “libboost_headers”,
    ],
    srcs : [
        “regex/src/**/*.cpp”,
    ],
    export_include_dirs: [“regex/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_system”,
    defaults: [“boost_library_defaults”],
    header_libs: [
        “libboost_headers”,
    ],
    srcs : [
        “system/src/**/*.cpp”,
    ],
    export_include_dirs: [“system/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}
cc_library {
    name: “libboost_thread”,
    defaults: [“boost_library_defaults”],
    //FIXME: build workaround
    cflags: [
        “-Wno-non-virtual-dtor”,
    ],
    header_libs: [
        “libboost_headers”,
    ],
    shared: {
        shared_libs: [
            “libboost_system”,
        ],
    },
    srcs : [
        “thread/src/**/*.cpp”,
    ],
    exclude_srcs : [
        “thread/src/win32/*.cpp”,
        “thread/src/pthread/once_atomic.cpp”,
    ],
    local_include_dirs : [
        “thread/src”,
        “thread/src/pthread”,
    ],
    export_include_dirs: [“thread/include”],
    export_header_lib_headers: [
        “libboost_headers”,
    ],
}

步骤3: 编译

联系方式

为了更好的反馈联系,个人留下了一些联系方式
微信:994052070
邮箱:994052070@qq.com
github: https://github.com/ByteXiaoTang

 类似资料: