【问题标题】:Android Studio Cmake cannot determine linker language for targetAndroid Studio Cmake 无法确定目标的链接器语言
【发布时间】:2019-03-26 02:42:28
【问题描述】:

我尝试将我的根 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

我的CMakeLists.txt 文件包含在src/min/cpp 中,以及它说找不到的iob.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 )

【问题讨论】:

  • 你能显示你项目的文件层次结构吗? BTW,通过命名cpp/子目录暗示了C++文件,你确定iob.c文件,对应C语言?

标签: android cmake android-ndk java-native-interface


【解决方案1】:

如果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 )

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多