使用CMAKE在Android项目中生成.H文件和.C文件

时间:2019-06-10 13:22:35

标签: android gradle cmake android-ndk

我希望使用CMAKE构建我的Android项目。 Android项目包含普通的Java文件,native-lib.cpp文件,一些.c文件和一些外部.h文件。

到目前为止,我已经使用了以下方法。这是我的CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

FILE(GLOB SOURCES path/to/external/c/files/*.c native-lib.cpp)

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

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        ${SOURCES}
        )

include_directories(
        path/to/folder1/containing/some/headers
        path/to/folder2/containing/some/headers
)

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

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

target_link_libraries( # Specifies the target library.
        native-lib

        ${log-lib})

我尝试构建该应用程序,但是期望零错误。虽然出现以下错误:

.../app/src/main/cpp/native-lib.cpp:23: error: undefined reference to 'foo()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

函数foo在一个外部C文件中定义,并在一个外部标头中定义,该标头包含在外部C文件和native_lib.cpp中。

0 个答案:

没有答案