Android Studio Cmake 无法确定目标的链接器语言

Raf*_*afa 6 java-native-interface android cmake android-ndk

我尝试将我的根app/文件链接到 C++ 项目,但不断收到此错误。

CMake Error at CMakeLists.txt:15 (add_library):


    src/main/cpp/iob.c


  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp


  .hxx .in .txx


CMake Error: CMake can not determine linker language for target: iob
Run Code Online (Sandbox Code Playgroud)

我把我的CMakeLists.txt文件src/min/cppiob.c它说找不到的文件放在一起。我究竟做错了什么?

这是我的 CMakeLists.txt

# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")

# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.

add_library( # Specifies the name of the library.
         iob

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/cpp/iob.c )
Run Code Online (Sandbox Code Playgroud)

Ale*_*ohn 8

如果CMakeLists.txtsrc/main/cpp目录中(这是 AS 向导生成 C++ 项目的方式),那么您应该说

add_library( # Specifies the name of the library.
     iob

     # Sets the library as a shared library.
     SHARED

     # Provides a relative path to your source file(s).
     iob.c )
Run Code Online (Sandbox Code Playgroud)

源文件的相对路径是相对于CMakeLists.txt.