Android Studio 包括 cpp headers
Android Studio include cpp headers
CMake 无法确定目标的链接器语言:CydiaSubstrate … 是我遇到的错误。我真的不明白我做错了什么,也找不到与通过 cmake 添加 headers 相关的任何内容。请参考以下代码:
# 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} )
您可以尝试使用此 link,它已在 android-ndk sample or this link 中被 Halim Qarroum
在其他相关 post 中关闭。
希望对您有所帮助。
您的代码正在尝试构建 2 个库:platinmods 和 CydiaSubstrate。但是,如果您的意图只是让 CydiaSubstrate.h 被 platinmods.cpp 使用,那么您的代码并没有按照您的意愿进行。猜猜你确实想要稍后,
- 在源代码中,执行
#include "CydiaSubstrate.h"
,并将 CydiaSubstrate.h 复制到与 platinmods.cpp 相同的目录中
- 里面只留下platinmod相关代码build.gradle,删除所有CydiaSubstrate相关行
- 如果您的头文件与源文件不在同一文件夹中,请使用 CMake 的 target_include_directories() like this
- 如果您有源代码备份该头文件,您也需要将该源文件添加到编译中(与 platinmods.cpp 相同)
- 打开 CydiaSubstrate.h 看看需要定义什么宏才能使用它,这很有帮助。
然后执行 build->clean,然后 build ->build apk 看看还有什么问题(并修复它们)。
CMake 无法确定目标的链接器语言:CydiaSubstrate … 是我遇到的错误。我真的不明白我做错了什么,也找不到与通过 cmake 添加 headers 相关的任何内容。请参考以下代码:
# 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} )
您可以尝试使用此 link,它已在 android-ndk sample or this link 中被 Halim Qarroum
在其他相关 post 中关闭。
希望对您有所帮助。
您的代码正在尝试构建 2 个库:platinmods 和 CydiaSubstrate。但是,如果您的意图只是让 CydiaSubstrate.h 被 platinmods.cpp 使用,那么您的代码并没有按照您的意愿进行。猜猜你确实想要稍后,
- 在源代码中,执行
#include "CydiaSubstrate.h"
,并将 CydiaSubstrate.h 复制到与 platinmods.cpp 相同的目录中
- 里面只留下platinmod相关代码build.gradle,删除所有CydiaSubstrate相关行
- 如果您的头文件与源文件不在同一文件夹中,请使用 CMake 的 target_include_directories() like this
- 如果您有源代码备份该头文件,您也需要将该源文件添加到编译中(与 platinmods.cpp 相同)
- 打开 CydiaSubstrate.h 看看需要定义什么宏才能使用它,这很有帮助。
然后执行 build->clean,然后 build ->build apk 看看还有什么问题(并修复它们)。