Android Studio包含cpp标头

时间:2018-09-20 01:53:50

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

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} )

2 个答案:

答案 0 :(得分:0)

您可以尝试使用此链接,该链接在android-ndk示例中已关闭,或者在其他相关帖子中被Halim Qarroum的{​​{3}}关闭了。

希望它可以为您提供帮助。

答案 1 :(得分:0)

您的代码正在尝试构建2个库:platinmods和CydiaSubstrate。但是,如果您的目的只是让platinmods.cpp使用CydiaSubstrate.h,则您的代码没有执行您想要的操作。确实猜到你想要以后,

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

然后进行构建->清理,然后构建->生成apk以查看剩下的问题(并修复问题)。