使用 Android NDK 构建基于 Make 的 C++ 项目

Build a Make based C++ project using Android NDK

我需要为 Android 项目构建 csparse library。项目支持Make构建系统。

我不熟悉 Make build 中 NDK 的使用。我使用 Androids CMake 工具链 构建基于 CMake 的项目。

我正在寻找有关使用 NDK 构建基于 Make 的 C++ 项目的指南。我不想手动写一个CMakeLists.txt用于使用CMake工具链构建项目,因为csparse项目中的源文件太多了!

感谢任何帮助!

好的,没那么难。似乎 CSparse 是一个独立的,不依赖于其他线性代数库,如 CHOLMOD、BLAS、LAPACK、Metis 等

这是我的 Android 项目中的 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.4.1)
include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/include/CSparse/Source
)

add_library( # Sets the name of the library.
        csparse-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        include/CSparse/Source/cs_add.c
        include/CSparse/Source/cs_amd.c
        include/CSparse/Source/cs_chol.c
        include/CSparse/Source/cs_cholsol.c
        include/CSparse/Source/cs_compress.c
        include/CSparse/Source/cs_counts.c
        include/CSparse/Source/cs_cumsum.c
        include/CSparse/Source/cs_dfs.c
        include/CSparse/Source/cs_dmperm.c
        include/CSparse/Source/cs_droptol.c
        include/CSparse/Source/cs_dropzeros.c
        include/CSparse/Source/cs_dupl.c
        include/CSparse/Source/cs_entry.c
        include/CSparse/Source/cs_ereach.c
        include/CSparse/Source/cs_etree.c
        include/CSparse/Source/cs_fkeep.c
        include/CSparse/Source/cs_gaxpy.c
        include/CSparse/Source/cs_happly.c
        include/CSparse/Source/cs_house.c
        include/CSparse/Source/cs_ipvec.c
        include/CSparse/Source/cs_leaf.c
        include/CSparse/Source/cs_load.c
        include/CSparse/Source/cs_lsolve.c
        include/CSparse/Source/cs_ltsolve.c
        include/CSparse/Source/cs_lu.c
        include/CSparse/Source/cs_lusol.c
        include/CSparse/Source/cs_malloc.c
        include/CSparse/Source/cs_maxtrans.c
        include/CSparse/Source/cs_multiply.c
        include/CSparse/Source/cs_norm.c
        include/CSparse/Source/cs_permute.c
        include/CSparse/Source/cs_pinv.c
        include/CSparse/Source/cs_post.c
        include/CSparse/Source/cs_print.c
        include/CSparse/Source/cs_pvec.c
        include/CSparse/Source/cs_qr.c
        include/CSparse/Source/cs_qrsol.c
        include/CSparse/Source/cs_randperm.c
        include/CSparse/Source/cs_reach.c
        include/CSparse/Source/cs_scatter.c
        include/CSparse/Source/cs_scc.c
        include/CSparse/Source/cs_schol.c
        include/CSparse/Source/cs_spsolve.c
        include/CSparse/Source/cs_sqr.c
        include/CSparse/Source/cs_symperm.c
        include/CSparse/Source/cs_tdfs.c
        include/CSparse/Source/cs_transpose.c
        include/CSparse/Source/cs_updown.c
        include/CSparse/Source/cs_usolve.c
        include/CSparse/Source/cs_util.c
        include/CSparse/Source/cs_utsolve.c
        )


add_library(native-lib SHARED native-lib.cpp)



find_library( # Sets the name of the path variable.
        log-lib

        log)

target_link_libraries( # Specifies the target library.
        native-lib

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib}

        csparse-lib
        )

希望这个回答对其他人有帮助。

https://developer.android.com/ndk/guides/other_build_systems covers using the NDK with build systems other than ndk-build and CMake. The last section 明确涵盖传统的 make 项目。