用Android studio关联已经生成好的.a文件,编译出现如下错误:
Error:error: linker command failed with exit code 1 (use -v to see invocation)
CMakeLists.txt如下:
# 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)
#C++编译
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(OpenSSL_DIR ${CMAKE_SOURCE_DIR}/keystore)
# 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(crypto STATIC IMPORTED)
add_library(ssl STATIC IMPORTED)
set_target_properties( # Specifies the target library.
crypto
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
${OpenSSL_DIR}/lib/${ANDROID_ABI}/libcrypto.a )
set_target_properties( # Specifies the target library.
ssl
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
${OpenSSL_DIR}/lib/${ANDROID_ABI}/libssl.a )
add_library( # Sets the name of the library.
keystore
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/keystore.cpp
)
# 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 )
include_directories( ${OpenSSL_DIR}/include )
# 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_include_directories(keystore PRIVATE
${OpenSSL_DIR}/include)
target_link_libraries( # Specifies the target library.
keystore
crypto
ssl
# Links the target library to the log library
# included in the NDK.
${log-lib} )
我的环境:
Android Studio 2.3.3
NDK:最新的ndk-bundle(应该是14r以上)
用Android studio关联已经生成好的.a文件,编译出现如下错误: Error:error: linker command failed with exit code 1 (use -v to see invocation)
CMakeLists.txt如下:
我的环境: Android Studio 2.3.3 NDK:最新的ndk-bundle(应该是14r以上)
测试过程 1.猜想是路径不对,路径不对报的是其他的错,所以路径肯定没问题 2.Android PLATFORM版本有问题,是否需要设置版本?