代码之家  ›  专栏  ›  技术社区  ›  Rafa

android studio cmake无法确定目标的链接器语言

  •  2
  • Rafa  · 技术社区  · 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
    

    我有我的 CMakeLists.txt 文件内部 src/min/cpp 随着 iob.c 文件上写着找不到。我做错什么了?

    这是我的 CMAKLISTS.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 )
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Alex Cohn    6 年前

    如果 CMakeLists.txt 是在 src/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 )
    

    源文件的相对路径是相对于 CMAKLISTS.TXT .