【问题标题】:Android Studio include cpp headersAndroid Studio 包含 cpp 标头
【发布时间】:2018-09-20 01:53:49
【问题描述】:

CMake 无法确定目标的链接器语言:CydiaSubstrate ... 是我得到的错误。我真的不明白我做错了什么,也找不到与通过 cmake 添加标题相关的任何内容。请参考以下代码:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
         platinmods

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/cpp/platinmods.cpp )

add_library( # Sets the name of the library.
         CydiaSubstrate

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/cpp/CydiaSubstrate.h )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

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 )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                   platinmods

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )

target_link_libraries( # Specifies the target library.
                   CydiaSubstrate

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )

【问题讨论】:

  • CydiaSubstrate.h是你的头文件吗?
  • 是的,这是我的头文件
  • 为什么不使用 #include<CydiaSubstrate.h> 将它包含在您的 c++ 文件中?我的意思是不要将它包含在 Cmake 文件中,而是包含在 platinmods.cpp
  • 我做了,但找不到文件
  • 你的c++文件和头文件是否保持在同一路径??

标签: android cmake android-ndk native header-files


【解决方案1】:

您的代码正在尝试构建 2 个库:platinmods 和 CydiaSubstrate。但是,如果您的意图只是让 platinmods.cpp 使用 CydiaSubstrate.h,那么您的代码并没有做您想做的事情。猜你以后确实想要,

  • 在源代码中,执行#include "CydiaSubstrate.h",并将您的 CydiaSubstrate.h 复制到与 platinmods.cpp 相同的目录中
  • build.gradle 中只保留 platinmod 相关代码,删除所有 CydiaSubstrate 相关行
  • 如果您的头文件与源文件不在同一个文件夹中,请使用 CMake 的 target_include_directories(),如 this
  • 如果您有源代码备份该头文件,您还需要将该源文件添加到编译中(与 platinmods.cpp 相同)
  • 打开 CydiaSubstrate.h 看看需要定义什么宏才能使用它,这很有帮助。

然后执行 build->clean,然后 build ->build apk 看看还有什么问题(并修复它们)。

【讨论】:

    【解决方案2】:

    您可以尝试使用已在android-ndk 示例或this link Halim Qarroum 在其他相关帖子中关闭的链接。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 2014-01-04
      • 2017-08-18
      • 2012-12-19
      • 2012-04-20
      • 2023-04-10
      • 2018-06-15
      相关资源
      最近更新 更多