我有一个项目,该项目具有armeabi-v7a文件夹,并使用libssl.a和libcrypto.a库。现在,我可以使用源代码c ++文件编译该项目,并将其用于项目中。
现在,我希望cmake创建一个可以在任何其他项目中使用的共享库。我对cmake不太了解
我尝试了什么?
cmake -DCMAKE_TOOLCHAIN_FILE=$(NDK_PATH)/build/cmake/android.toolchain.cmake -DANDROID_NDK=$(NDK_PATH) -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-21 -DANDROID_STL=c++_shared -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/some_dir/
运行此
-- Check for working C compiler: $(NDK_PATH)/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
-- Check for working C compiler: $(NDK_PATH)/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: $(NDK_PATH)/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
-- Check for working CXX compiler: $(NDK_PATH)/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
CMAKE_CXX_COMPILER= /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: $(PATH)
现在,当我尝试运行
make
它给了我
Scanning dependencies of target dcsdk
Building CXX object CMakeFiles/dcsdk.dir/src/main/cpp/DCSDK.cpp.o
Building CXX object CMakeFiles/dcsdk.dir/src/main/cpp/Constants.cpp.o
Linking CXX shared library libdcsdk.dylib
ld:警告:ld:警告:忽略文件openssl-armeabi-v7a / lib / libssl.a,该文件是为不是链接架构的归档文件而构建的(x86_64):openssl-armeabi-v7a / lib / libssl .a忽略文件openssl-armeabi-v7a / lib / libcrypto.a,该文件是为归档而构建的,而不是要链接的体系结构(x86_64):openssl-armeabi-v7a / lib / libcrypto.a
体系结构x86_64的未定义符号: “ _OPENSSL_init_ssl”,引用自: DCSDK.cpp.o中的initSSL()
现在我遇到的问题是它是针对x86_64架构进行编译的,但是我已经在cmake中指定了它以使用ANDROID_ABI来实现armeabi-v7a。
如果您需要我的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)
# 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.
dcsdk
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp src/main/cpp/DCSDK.cpp src/main/cpp/Constants.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-armeabi-v7a/include/)
include_directories(/System/Library/Frameworks/JavaVM.framework/Headers/)
# 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.
dcsdk
# Links the target library to the log library
# included in the NDK.
${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libssl.a
${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libcrypto.a )