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

6

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

我在src/min/cpp目录下有一个名为CMakeLists.txt的文件和一个iob.c文件,但是程序提示找不到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 )

你能展示一下你项目的文件层次结构吗?顺便说一下,通过将子目录命名为 cpp/,暗示其中有 C++ 文件,那么你确定 iob.c 文件对应的是 C 语言吗? - Tsyvarev
1个回答

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 )

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接