Compile with CMAKE and invalid sh_info in symbol table - android

sorry bad english
cloned and compiled this project in Android Studio:
https://github.com/Pangu-Immortal/KeepAlivePerfect/
During compile, got the following error (using ndk 24.0.8215888):
KeepAlivePerfect/library/src/main/cpp/binder_libs/armeabi-v7a/libbinder.so: invalid sh_info in symbol table
tested both in linux and windows. Same error.
plz help

Finally could compile with changing SHARED to STATIC in CMakeLists.txt. And some more config.
Here are the changes:
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)
add_compile_options(-fno-rtti -O3 -v)
message(###${CMAKE_CURRENT_SOURCE_DIR})
link_directories(binder_libs/${CMAKE_ANDROID_ARCH_ABI})
aux_source_directory(. SRC_LIST) # 搜索当前目录下的所有.cpp文件
add_library( # Sets the name of the library.
keep_alive
# Sets the library as a shared library.
STATIC # Changed from SHARED to STATIC
# 提供源文件的相对路径。
${SRC_LIST} main.cpp art.cpp)
# More Config
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libutils.so)
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libc.so)
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libcutils.so)
set_target_properties(keep_alive PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/binder_libs/${ANDROID_ABI}/libutils.so)
# The END
find_library(log-lib log)
target_link_libraries(
keep_alive
${log-lib}
)
More information in an issue in main project:
https://github.com/Pangu-Immortal/KeepAlivePerfect/issues/8#issuecomment-1107427875

Related

Issue linking against POCO::Net::SocketAddress

I'm working on an Android native project where I'm using NDK + CMake to build a native solution based on POCO C++. I'm getting a super weird link error when I comment this line in my cpp file:
//std::ostream& o = session.sendRequest(request);
this is the link error:
../NetSSL_OpenSSL/src/SecureSocketImpl.cpp:381: error: undefined reference to 'Poco::Net::SocketAddress::~SocketAddress()'
But is even more weird that the file with the object where sendRequest is placed it is not being included in any other file. So, I have one isolated file (header and implementation) that is not being included in any other file (but it is build with CMake, I cannot remove it because of the issue) and if I comment one line of the implementation, it generates a link issue.
This is how I'm linking Poco:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_COMPILER_VERSION "5.0") # Unknown miss-detection of the compiler by CMake
find_library( # Defines the name of the path variable that stores the
# location of the NDK library.
log-lib
# Specifies the name of the NDK library that
# CMake needs to locate.
log )
add_library(PocoFoundation STATIC IMPORTED)
set_target_properties(PocoFoundation PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoFoundation.a)
add_library(PocoNet STATIC IMPORTED)
set_target_properties(PocoNet PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoNet.a)
add_library(PocoJSON STATIC IMPORTED)
set_target_properties(PocoJSON PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoJSON.a)
add_library(PocoNetSSL STATIC IMPORTED)
set_target_properties(PocoNetSSL PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoNetSSL.a)
add_library(PocoCrypto STATIC IMPORTED)
set_target_properties(PocoCrypto PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoCrypto.a)
add_library(PocoUtil STATIC IMPORTED)
set_target_properties(PocoUtil PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoUtil.a)
add_library(PocoXML STATIC IMPORTED)
set_target_properties(PocoXML PROPERTIES IMPORTED_LOCATION
/Users/user/dev/poco-2/install/lib/libPocoXML.a)
// ... SOURCES ...
target_include_directories(mylib PRIVATE /Users/user/dev/poco-2/install/include)
target_link_libraries(mylib
PocoNet
PocoNetSSL
PocoUtil
PocoJSON
PocoCrypto
PocoXML
PocoFoundation
Ssl
Crypto
${log-lib})
Also, I'm using Android Studio 3.6.2 with NDK version r19c. I have tried cleaning the build, rebuilding and cleaning .cxx, .gradle and build folder.
Any idea?
You need to recreate the inter-library dependencies such that CMake can construct the correct linker command line with dependencies after the libraries that depend on them.
Running through the libraries you listed, that should be at least the following (reconstructed from the Poco CMakeLists.txt).
target_link_libraries(PocoNet PocoFoundation)
target_link_libraries(PocoNetSSL PocoCrypto PocoUtil PocoNet)
target_link_libraries(PocoCrypto PocoFoundation Ssl Crypto)
target_link_libraries(PocoUtil PocoFoundation)
target_link_libraries(PocoJSON PocoFoundation)
target_link_libraries(PocoXML PocoFoundation)

Add headers and native library to Android project

I got some C code I have to integrate into my Android project. It depends on a library (.so), and I also have the .h files.
I copied the libs and include directories into the project's cpp package to make them easier to find.
To make it easier I tried starting with the HelloJNI project Android Studio offers and followed the instructions here.
This is the CMakeLists.txt:
#given from HelloJNI
cmake_minimum_required(VERSION 3.4.1)
add_library(hello-jni SHARED
hello-jni.c)
# Include libraries needed for hello-jni lib
target_link_libraries(hello-jni
android
log)
#my own additions now:
add_library( # Specifies the name of the library.
libgdndk
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
IMPORTED)
set_target_properties( # Specifies the target library.
libgdndk
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
${CMAKE_BINARY_DIR}/libs/${ANDROID_ABI}/libgdndk.so )
include_directories(${CMAKE_BINARY_DIR}/inc/)
target_link_libraries( hello-jni libgdndk app-glue ${libgdndk} )
This results in an error:
ninja: error: 'libs/armeabi-v7a/libgdndk.so', needed by 'C:/workspace/android/HelloJNI/app/build/intermediates/cmake/arm7/debug/obj/armeabi-v7a/libhello-jni.so', missing and no known rule to make it
You seem to be linking your imported library to the hello-jni target twice. Also, using ${} in the target_link_libraries() command for the libgdndk library is not necessary. You have already defined a CMake target libgdndk for the library, so you can just do this:
target_link_libraries( hello-jni libgdndk app-glue )
I finally got some help from the publisher of the lib, the (working) result looks quite similar to the code i tried, so maybe it was just the location of the library that was at fault.
add_library( gdndk SHARED IMPORTED )
include_directories( $ENV{userprofile}/AppData/Local/Android/sdk/extras/blackberry/dynamics_sdk/sdk/libs/handheld/gd/inc)
set_target_properties(gdndk PROPERTIES IMPORTED_LOCATION $ENV{userprofile}/AppData/Local/Android/sdk/extras/blackberry/dynamics_sdk/sdk/libs/handheld/gd/libs/${ANDROID_ABI}/libgdndk.so )
target_link_libraries( hello-jni gdndk )

java.lang.UnsatisfiedLinkError: Couldn't load NativeMorphoSmartSDK_6.13.2.0-4.1 from loader dalvik.system.PathClassLoader

I am getting null UnsatisfiedLinkError while building my app.
i am using openssl and some third party libraries to capture finger and verify them.
here is my cmake file
# 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.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
add_library(openssl SHARED IMPORTED)
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libcrypto.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libssl.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libidkit.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libjnidispatch.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libMSO100.so )
set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libNativeMorphoSmartSDK_6.13.2.0-4.1.so )
# 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.
include_directories(openssl-armeabi-v7a/include/)
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.
native-lib
${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libcrypto.a
${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libssl.a
# Links the target library to the log library
# included in the NDK.
${log-lib} )
is this correct way of loading .so file in cmake or is there any method to load .so files . help with this issue
Each .so file that you list is a separate library. You must give each a separate name, e.g.
add_library(foo SHARED IMPORTED)
set_target_properties (foo PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libcrypto.so )
add_library(prebuilt_ssl SHARED IMPORTED)
set_target_properties (prebuilt_ssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libssl.so )
add_library(idkit SHARED IMPORTED)
set_target_properties (idkit PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libidkit.so )
and so on. As you can see above, the logical name is not necessarily related to the file name.
If your native-lib depends on some of them, you can use these names:
target_link_libraries( # Specifies the target library.
native-lib foo prebuilt_ssl
# Links the target library to the log library
# included in the NDK.
log )
Note that with NDK, you don't need find_library to add dependency on the android log library.
There is some self-contradiction in the CMake script that you posted. You should use OpenSSL libraries either as shared objects (as libssl.so), or static libraries (as libssl.a), but not both. It's OK to mix libjnidispatch.so together with libssl.a, but not libcrypto.a and libssl.so.

Linker error. Android Studio with C++ support using CMakeLists.txt Intel OpenCL SDK 2015 with Android support

Question Update:
Linker error
I installed Intel OpenCL SDK with Android Support on dev pc.
Difficulty building Android Studio Solution with C++ support using CMakelists.txt
OpenCL & OpenCV in Android Studio using CMakeLists.txt
CMakeLists.txt:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
#Added 2 path definitions to support 20160825 additions
set(pathToProject C:/Users/eogha/Desktop/HelloOpenCV)
set(pathToOpenCv C:/OpenCV-3.1.0-android-sdk)
set(pathToOpenCL "C:/Program Files (x86)/Intel/OpenCL SDK/5.3")
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
#Addition suggested by Bruno Alexandre Krinski 20160825
include_directories(${pathToOpenCv}/sdk/native/jni/include )
include_directories(${pathToOpenCL}/include)
# 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( native-lib SHARED src/main/cpp/native-lib.cpp )
#Addition suggested by Bruno Alexandre Krinski 20160825
add_library( lib_opencv SHARED IMPORTED )
#Addition suggested by Bruno Alexandre Krinski 20160825
set_target_properties( lib_opencv PROPERTIES IMPORTED_LOCATION
${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so )
add_library( lib_opencl SHARED IMPORTED )
set_target_properties( lib_opencl PROPERTIES IMPORTED_LOCATION "C:/Program
Files (x86)/Intel/OpenCL SDK/5.3/lib/android64/libOpenCL.so" )
# 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( native-lib $\{log-lib} lib_opencv lib_opencl )
Android Studio Error: linker command failed with exit code 1 (use -v to see invocation)
Finally !! The OpenCL Shared Object library seems to be imported into the android project structure. But now I have this linker error. How do I resolve this in Windows 10 ??

Import "prebuilt library" in Android-Studio (NDK SUPPORT)

Hi I'm making a android app in Android Studio (ver 2.3 - NDK SUPPORT)
I have a problem with importing library (dlib)
I downloaded source code from https://github.com/tzutalin/dlib-android and built it
I copied .so file(libandroid_dlib.so) to app/src/main/JniLibs/armeabi-v7a folder
I changed a CMakeLists.txt settings
I loaded library from MainActivity.java file
My code has no errors but when I import dlib like above, my app doesn't work anything !
Is there a missed step? THANK YOU SO MUCH IN ADVANCE
MainActivity.java
static {
System.loadLibrary("opencv_java3");
System.loadLibrary("android_dlib");
System.loadLibrary("imported-lib");
System.loadLibrary("native-lib");
}
CMakeLists.txt
set(pathOPENCV /Users/gicheonkang/OpenCV-android-sdk)
set(pathPROJECT /Users/gicheonkang/AndroidStudioProjects/HelloWorld)
set(pathLIBOPENCV_JAVA ${pathPROJECT}/app/src/main/JniLibs/${ANDROID_ABI}/libopencv_java3.so)
set(pathDLIB /Users/gicheonkang/dlib)
set(pathLIBDLIB ${pathPROJECT}/app/src/main/JniLibs/${ANDROID_ABI}/libandroid_dlib.so)
cmake_minimum_required(VERSION 3.4.1)
# CMAKE settings
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
# include *.cpp and *.h file
file(GLOB Library_SOURCES_FACEANALYSER src/main/cpp/FaceAnalyser/*.cpp)
file(GLOB Library_HEADERS_FACEANALYSER src/main/cpp/FaceAnalyser/*.h)
include_directories(${pathOPENCV}/sdk/native/jni/include)
include_directories(${pathDLIB}/dlib)
# 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 it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/native-lib.cpp )
add_library( lib_opencv SHARED IMPORTED )
add_library( dlib SHARED IMPORTED )
add_library( imported-lib SHARED ${Library_SOURCES_FACEANALYSER} ${Library_HEADERS_FACEANALYSER})
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathLIBOPENCV_JAVA})
set_target_properties( dlib PROPERTIES IMPORTED_LOCATION ${pathLIBDLIB})
set_target_properties( imported-lib PROPERTIES LINKER_LANGUAGE CXX )
find_library( log-lib log )
find_library( android-lib android)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
imported-lib
# Links the target library to the log library
# included in the NDK.
lib_opencv
#here is the problem
#dlib
)
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
${android-lib}
#imported-lib
lib_opencv
#here is the problem!!!!!!
#dlib
)

Categories

Resources