Issue linking against POCO::Net::SocketAddress - android

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)

Related

How to build and run and and React Native Android CMake App (JNI)

I've been trying to compile and run an Android / ReactNative CMake project, but it fails to run whenever I make the library shared. I get the error that the header files for lib_gmath ,lib_gperf,libsqliteX cannot be found during build.
../../../../src/main/jni/hello-libs.cpp:21:10: fatal error: 'gmath.h' file not found
#include <gmath.h>
However, everything compiles OK when I change ${LIB_GEN_PERS} to static, but then I get a runtime error :
java.lang.UnsatisfiedLinkError: dlopen failed: library "lib-gen-lib-pers.so" not found
What am I doing wrong?
Thank you all in advance.
CMake.txt
cmake_minimum_required(VERSION 3.6.0)
project(gen-lib-pers)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(LIB_GEN_PERS "gen-lib-pers")
add_library(${LIB_GEN_PERS} SHARED)
find_library(log-lib log)
## LIB DIRECTORIES
set(RES_LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/res/libs)
add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES
IMPORTED_LOCATION ${RES_LIBS_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a
INCLUDE_DIRECTORIES ${RES_LIBS_DIR}/gmath/include
)
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES
IMPORTED_LOCATION ${RES_LIBS_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so
INCLUDE_DIRECTORIES ${RES_LIBS_DIR}/gperf/include
)
add_library(libsqliteX SHARED IMPORTED)
set_target_properties(libsqliteX PROPERTIES
IMPORTED_LOCATION ${RES_LIBS_DIR}/sqlite3/lib/${ANDROID_ABI}/libsqliteX.so
INCLUDE_DIRECTORIES ${RES_LIBS_DIR}/sqlite3/include
)
add_library(hello-libs STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/hello-libs.cpp)
target_link_libraries(hello-libs
lib_gmath
lib_gperf
libsqliteX
android
${log-lib}
)
target_link_libraries(${LIB_GEN_PERS} hello-libs)

Compile with CMAKE and invalid sh_info in symbol table

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

Error about non-requested dependency when trying to build an Android lib using CMake

I'm trying to build an Android lib with Gradle and CMake. I'm adding OpenSSL like that:
add_library(Ssl STATIC IMPORTED)
set_target_properties(Crypto PROPERTIES IMPORTED_LOCATION
/Users/user/dev/android_openssl/static/lib/${ANDROID_ABI}/lib/libssl.a)
But the build is failing with this message:
ninja: error: 'Ssl-NOTFOUND', needed by 'lib/libmylib.so', missing and no known rule to make it
In build.ninja file the lib is appearing as is: Ssl-NOTFOUND before libssl.a with the right path
Any idea about why I have this dependency which is created by CMake?
EDIT
The issue was a bad target property:
add_library(Ssl STATIC IMPORTED)
set_target_properties(Ssl PROPERTIES IMPORTED_LOCATION
/Users/user/dev/android_openssl/static/lib/${ANDROID_ABI}/lib/libssl.a)

Trying to run Python on Android - With cmake

I know this is a long shot.
So using this GitHub Python project I am currently able to run Python on Android building with an experimental version of gradle. We are trying to upgrade to mainline gradle and the newest Android Studio, so we are trying to build all our NDK stuff with cMake. We have everything so that it will run, but as soon as we launch Python it says it fails to import _socket.
We have all the same assests and Python in the project, we have included all of the shared libraries so that thinks compile and link. Any ideas what is missing that I can't import the socket stuff? I assume this is a c module that it's trying to import and run, but can't understand what would be different that it can't find it.
cmake_minimum_required(VERSION 3.4.1)
project(workflow)
set(CMAKE_ANDROID_STL_TYPE gnustl_shared)
set(CMAKE_SYSTEM_VERSION 23)
# configure directory variables for use throughout this file
set(distribution_dir ${CMAKE_SOURCE_DIR}/../jniLibs)
set(jni_src_dir ${CMAKE_SOURCE_DIR}/../jni)
# set all our include directories (header locations)
include_directories(${jni_src_dir}/asr/inc
${jni_src_dir}/ext/android/audioin/inc
${jni_src_dir}/asr
${jni_src_dir}/python
${jni_src_dir}/pdd
${jni_src_dir}/pdd/os
${jni_src_dir}
)
# define the 3rd party libraries to include in this project
# this includes all Nuance stuff, and our custom built python lib
add_library(libgenericdca SHARED IMPORTED)
set_target_properties(libgenericdca PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libgenericdca.so)
add_library(libvocon3200_sem SHARED IMPORTED)
set_target_properties(libvocon3200_sem PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_sem.so)
add_library(libpal_audio SHARED IMPORTED)
set_target_properties(libpal_audio PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpal_audio.so)
add_library(libpal_core SHARED IMPORTED)
set_target_properties(libpal_core PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpal_core.so)
add_library(libpython35m SHARED IMPORTED)
set_target_properties(libpython35m PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpython3.5m.so)
add_library(libvocon3200_asr SHARED IMPORTED)
set_target_properties(libvocon3200_asr PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_asr.so)
add_library(libvocon3200_base SHARED IMPORTED)
set_target_properties(libvocon3200_base PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_base.so)
add_library(libvocon3200_gram2 SHARED IMPORTED)
set_target_properties(libvocon3200_gram2 PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_gram2.so)
add_library(libvocon3200_platform SHARED IMPORTED)
set_target_properties(libvocon3200_platform PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_platform.so)
add_library(libvocon3200_pron SHARED IMPORTED)
set_target_properties(libvocon3200_pron PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_pron.so)
add_library(libvocon3200_sem3 SHARED IMPORTED)
set_target_properties(libvocon3200_sem3 PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon3200_sem3.so)
add_library(libvocon_ext_heap SHARED IMPORTED)
set_target_properties(libvocon_ext_heap PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon_ext_heap.so)
add_library(libvocon_ext_stream SHARED IMPORTED)
set_target_properties(libvocon_ext_stream PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libvocon_ext_stream.so)
# set various C and CXX(++) flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
# recursive wildcard search to find all the right cpp and c source files to compile
file(GLOB_RECURSE source_files ${jni_src_dir}/asr/*.cpp
${jni_src_dir}/ext/android/audioin/src/*.c
${jni_src_dir}/asr/*.cpp
${jni_src_dir}/pdd/*.cpp
${jni_src_dir}/pdd/os/*.cpp
${jni_src_dir}/*.cpp)
SET( workflow_source ${source_files})
# finally, set up our workflow library and attach the source files above (this causes cmake to compile the sources)
add_library(workflow SHARED ${workflow_source})
# set our workflow library to be C++
SET_TARGET_PROPERTIES (workflow PROPERTIES LINKER_LANGUAGE CXX)
# lastly, set to link against the 3rd party libs above
target_link_libraries(workflow
android
libgenericdca
libvocon3200_sem
libpal_audio
libpal_core
libpython35m
libvocon3200_asr
libvocon3200_base
libvocon3200_gram2
libvocon3200_platform
libvocon3200_pron
libvocon3200_sem3
libvocon_ext_heap
libvocon_ext_stream
log
atomic)
Android Studio 3 was released and around the same time Gradle 4.1 was released. Now with using both of these I'm able to build and run Python without issue.
I'm assuming the Gradle 4.1 release had some change that fixed my issue.

lib.so missing and no known rule to make it

From google examples I'm trying to customize hello-libs example addind my shared library libofr_engine_core
but i receive this error...
Error:error: 'C:/Users/.../Downloads/android-ndk-master/hello-libs/distribution/ofr/lib/arm64-v8a/libofr_engine_core.so', needed by 'C:/Users/.../Downloads/android-ndk-master/hello-libs/app/build/intermediates/cmake/debug/obj/arm64-v8a/libhello-libs.so', missing and no known rule to make it
What I'm doing wrong?
Obviously I have added the .so and .h to my distribution folder
cmake_minimum_required(VERSION 3.4.1)
# configure import libs
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution)
add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a)
# shared lib will also be tucked into APK and sent to target
# refer to app/build.gradle, jniLibs section for that purpose.
# ${ANDROID_ABI} is handy for our purpose here. Probably this ${ANDROID_ABI} is
# the most valuable thing of this sample, the rest are pretty much normal cmake
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
add_library(libofr_engine_core SHARED IMPORTED)
set_target_properties(libofr_engine_core PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/ofr/lib/${ANDROID_ABI}/libofr_engine_core.so)
# build application's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(hello-libs SHARED
hello-libs.cpp)
target_include_directories(hello-libs PRIVATE
${distribution_DIR}/gmath/include
${distribution_DIR}/gperf/include
${distribution_DIR}/ofr/include
)
target_link_libraries(hello-libs
android
lib_gmath
lib_gperf
libofr_engine_core
log)

Categories

Resources