error: undefined reference to 'cv::String::deallocate()' - android

I try to add opencv lib to my native android project. In order to do it I added path to opencv to 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
cmake_minimum_required(VERSION 3.4.1)
set(pathToOpenCv D:\\OpenCV-android-sdk)
set(CMAKE VERBOSE MAKEFILE on)
set(CMAKE CXX FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(PARSER_TET_DIR ../../../co_FileCodec)
set(PARSER__DIR_ENGINE ../../../co_FileCodec_Engine/co_DecoderEngine)
set(PARSER_GWS_DIR ../../../GWStdLib)
include_directories(${pathToOpenCv}/sdk/native/jni/include)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION
${pathToOpenCv}/sdk/native/libs/${CMAKE_ANDROID_ARCH_ABI}/libopencv_java3.so)
set(decoder_engine_source
src/main/cpp/co_DecoderEngineAndroidApi.cpp
src/main/cpp/texture_decoder/texture_codec.cpp
src/main/cpp/util/util.cpp
)
add_library( # Sets the name of the library.
co_decoder_engine_android_lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${decoder_engine_source} )
# libcodec
set(_codec_source
${PARSER__DIR}/co_Decoder/co_MtrDecoder.cpp
${PARSER__DIR}/co_Decoder/co_Decoder.cpp
)
add_library(libcodec SHARED ${_codec_source})
include_directories(src/main/cpp)
include_directories(${PARSER__DIR})
include_directories(${PARSER__DIR}/co_Decoder)
include_directories(${PARSER__DIR}/co_Shared)
include_directories(${PARSER_GWS_DIR})
include_directories(${PARSER__DIR_ENGINE})
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 )
target_compile_options(co_decoder_engine_android_lib PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
target_compile_options(libcodec PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
target_link_libraries( # Specifies the target library.
co_decoder_engine_android_lib
mediandk
android
lib_opencv
libcodec
${log-lib} )
and then I try to add this include #include "opencv2/opencv.hpp" to my .cpp file
but I get such error
ninja: Entering directory `D:\co_repo\com_main\co_Infrastructure\Tier1.0\co_FileCodec_Engine\DecoderEngineBuilder\co_decoder_engine_android\.cxx\cmake\debug\x86'
[1/3] Building CXX object CMakeFiles/libcodec.dir/01a7033fdca6735bc52cb367da99f647/co_DecoderEngine/co_DecoderStream.cpp.o
[2/3] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86\liblibcodec.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/x86/liblibcodec.so
cmd.exe /C "cd . && C:\Users\track\AppData\Local\Android\Sdk\ndk\20.0.5594570\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android24 --gcc-toolchain=C:/Users/track/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/track/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -std=c++17 -Wall -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,liblibcodec.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86\liblibcodec.so CMakeFiles/libcodec.dir/e17dc0da4ce9741e6542b9ad403a181e/co_FileCodec/co_Decoder/co_MtrDecoder.cpp.o CMakeFiles/libcodec.dir/e17dc0da4ce9741e6542b9ad403a181e/co_FileCodec/co_Decoder/co_Decoder.cpp.o CMakeFiles/libcodec.dir/a4eab3dee2189f67213cbef1e5027e5a/co_Decoder/co_DecoderImpl.cpp.o CMakeFiles/libcodec.dir/a4eab3dee2189f67213cbef1e5027e5a/co_Decoder/co_ChunkBuffers.cpp.o CMakeFiles/libcodec.dir/e17dc0da4ce9741e6542b9ad403a181e/co_FileCodec/co_Shared/co_Texture.cpp.o CMakeFiles/libcodec.dir/D_/co_repo/com_main/co_Infrastructure/Tier1.0/GWStdLib/GWS_Basics.cpp.o CMakeFiles/libcodec.dir/01a7033fdca6735bc52cb367da99f647/co_DecoderEngine/co_DecoderStream.cpp.o -latomic -lm && cd ."
D:/OpenCV-android-sdk/sdk/native/jni/include\opencv2/core/cvstd.hpp:648: error: undefined reference to 'cv::String::deallocate()'
D:/OpenCV-android-sdk/sdk/native/jni/include\opencv2/core/cvstd.hpp:656: error: undefined reference to 'cv::String::deallocate()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I have already checked everything, what am I doing wrong?

If nm (dumpbin.exe for Windows) sees cv::String::deallocate() in libopencv_java3.so:
$ nm -CD libopencv_java3.so | grep cv::String::deallocate
00000000003e3fa0 T cv::String::deallocate()
It means that something wrong with your wrapping lib_opencv stuff. Let's try to test it with real absolute path to libopencv_java3.so (copy it from your file manager program) and add it directly to target_link_libraries(co_decoder_engine_android_lib ...) and compile it for selected ABI.

Related

Read the format of a static library to know how to import it on MacOS

I have a big library that uses the NDK to run some native code.
With the new version I need to replace a library that was build from the source code with static libraries that are provided as a set of prebuilt .a libraries.
I have configured the project to import these libraries like this:
cmake_minimum_required (VERSION 3.10)
set(CMAKE_CXX_STANDARD 14)
add_definitions(-DNO_USE_SPLICE)
# Provide build env vars for http.c now that we are using shared jitter_client repo
add_definitions(-Wdeprecated-declarations -DVERSION="android" -DREVISION="1" -DPROGRAMNAME="sksdk" -DBUILDLINK="android" -DBUILDTIME="built_at_TODO")
add_definitions(-D_Exit=exit)
add_definitions(-D__UAPI_DEF_IF_IFNAMSIZ=1)
include_directories(../../external/cpp
../../external/cpp/libcompany/src
src/main/cpp)
add_library( # Specifies the name of the library.
mynativelib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/cpp_to_jobj/common_convert_cpp_to_jobj.cpp
src/main/cpp/cpp_to_jobj/thread_utils.cpp
src/main/cpp/cpp_to_jobj/utf8_scrubber.cpp
src/main/cpp/jni_utils.cpp
src/main/cpp/logging_utils.cpp
src/main/cpp/android_remote_logging.c
src/main/cpp/executor.cpp)
add_library(curl STATIC IMPORTED)
set_target_properties(curl
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/libs/curl/${ANDROID_ABI}/libcurl.so)
target_compile_definitions(
mynativelib
PRIVATE
ANDROID
)
target_link_libraries(
mynativelib
curl
${CMAKE_SOURCE_DIR}/libs/static/${ANDROID_ABI}/libmystaticlib.a
... other libs here. These are fine ...
)
When I build the library I get the error:
../../../../libs/static/arm64-v8a/libmystaticlib.a: error adding symbols: File format not recognized
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Here the relevant part of the stacktrace:
Caused by: Build command failed.
Error while executing process /Users/rrr/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/rrr/myproject/p12345/p12345-android-sdk/sdk/p12345module/.cxx/cmake/release/arm64-v8a mynativelib}
ninja: Entering directory `/Users/rrr/myproject/p12345/p12345-android-sdk/sdk/p12345module/.cxx/cmake/release/arm64-v8a'
[1/1] Linking CXX shared library ../../../../build/intermediates/cmake/release/obj/arm64-v8a/libmynativelib.so
FAILED: ../../../../build/intermediates/cmake/release/obj/arm64-v8a/libmynativelib.so
: && /Users/rrr/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/rrr/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/rrr/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O2 -DNDEBUG -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libmynativelib.so -o ../../../../build/intermediates/cmake/release/obj/arm64-v8a/libmynativelib.so CMakeFiles/mynativelib.dir/src/main/cpp/cpp_to_jobj/common_convert_cpp_to_jobj.cpp.o CMakeFiles/mynativelib.dir/src/main/cpp/cpp_to_jobj/thread_utils.cpp.o CMakeFiles/mynativelib.dir/src/main/cpp/cpp_to_jobj/utf8_scrubber.cpp.o CMakeFiles/mynativelib.dir/src/main/cpp/jni_utils.cpp.o CMakeFiles/mynativelib.dir/src/main/cpp/logging_utils.cpp.o CMakeFiles/mynativelib.dir/src/main/cpp/android_remote_logging.c.o CMakeFiles/mynativelib.dir/src/main/cpp/test_executor.cpp.o -L/Users/rrr/myproject/p12345/p12345-android-sdk/sdk/p12345module/libs/routerAgent/shared/arm64-v8a ../../../../libs/curl/arm64-v8a/libcurl.so ../../../../libs/routerAgent/static/arm64-v8a/libmystaticlib.a -lavformat -lavcodec -lavutil -ljansson ../../../../libs/routerAgent/static/arm64-v8a/libabctytt_wrapper.a ../../../../libs/routerAgent/static/arm64-v8a/libp12345_logging.a ../../../../libs/routerAgent/static/arm64-v8a/libabctytt.a ../../../../libs/routerAgent/static/arm64-v8a/libabcwebfetcher.a ../../../../libs/routerAgent/static/arm64-v8a/libabctargetconfig_core.a ../../../../libs/routerAgent/static/arm64-v8a/libabctargetconfig_config_parsing.a ../../../../libs/routerAgent/static/arm64-v8a/libabctargetconfig_common.a ../../../../libs/routerAgent/static/arm64-v8a/libp12345_latency.a ../../../../libs/routerAgent/static/arm64-v8a/libabc_sk.a ../../../../libs/routerAgent/static/arm64-v8a/libp12345_http.a ../../../../libs/routerAgent/static/arm64-v8a/libp12345_thread.a -latomic -lm && :
../../../../libs/routerAgent/static/arm64-v8a/libmystaticlib.a: error adding symbols: File format not recognized
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Please notice that I'm not sure whether the version of cmake that I'm using is the same as the one used to build the libraries.
I'm using the the NDK: 21.1.6352462
To investigate the issue I tried some tools that people suggested in similar questions.
With ar I get an error:
ar -x libmystaticlib.a
ar: /: Is a directory
ar: adaptive.c.o/: No such file or directory
ar: coro.c.o/: No such file or directory
ar: curlops.c.o/: No such file or directory
ar: entities.c.o/: No such file or directory
ar: exception.c.o/: No such file or directory
ar: getinfo.c.o/: No such file or directory
ar: helper.c.o/: No such file or directory
ar: metrics.c.o/: No such file or directory
ar: mm_parser.c.o/: No such file or directory
I have also tried with file and objdump that both do not return any information.
Is there a way to know what goes wrong?

Android Studio NDK :: Error: Unknown type name '__va_list'

In our application want to integrate OpenCV c/c++ library. I have successfully integrate OpenCV library but when try to build using android NDK r12b getting below build error.
Build command failed.
Error while executing process C:\Users\Dell\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build D:\Project\WorkSpace\AndroidStudio\Sample\Sample2NativeSample\app\.externalNativeBuild\cmake\debug\x86 --target native-lib}
[0/1] Re-running CMake...
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/.externalNativeBuild/cmake/debug/x86
[1/150] Building CXX object CMakeFiles/native-lib.dir/src/features/RVUPHistogramFeature.cpp.o
FAILED: CMakeFiles/native-lib.dir/src/features/RVUPHistogramFeature.cpp.o
D:\Project\Android\android-ndk-r12b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target i686-none-linux-android -gcc-toolchain D:/Project/Android/android-ndk-r12b/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=D:/Project/Android/android-ndk-r12b/platforms/android-15/arch-x86 -Dnative_lib_EXPORTS -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/algorithm -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/deps/msvc/sys -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/features -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/opencv -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/opencv2/imgproc -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/opencv2/core -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/opencv2/ml -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/opencv2 -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/prediction -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/wsq -ID:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include -isystem D:/Project/Android/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem D:/Project/Android/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include -isystem D:/Project/Android/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fexceptions -frtti -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/features/RVUPHistogramFeature.cpp.o -MF CMakeFiles\native-lib.dir\src\features\RVUPHistogramFeature.cpp.o.d -o CMakeFiles/native-lib.dir/src/features/RVUPHistogramFeature.cpp.o -c D:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/src/features/RVUPHistogramFeature.cpp
In file included from D:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/src/features/RVUPHistogramFeature.cpp:1:
In file included from D:/Project/WorkSpace/AndroidStudio/Sample/Sample2NativeSample/app/src/main/cpp/include/features\RVUPHistogramFeature.h:4:
D:/Project/Android/android-ndk-r12b/platforms/android-15/arch-x86/usr/include\stdio.h:257:37: `*error: unknown type name '__va_list'; did you mean 'va_list'?*`
int vfprintf(FILE *, const char *, __va_list);
^
D:\Project\Android\android-ndk-r12b\toolchains\llvm\prebuilt\windows-x86_64\bin\..\lib64\clang\3.8.256229\include\stdarg.h:30:27: note: 'va_list' declared here
typedef __builtin_va_list va_list;
Here, check my CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
include_directories(include/algorithm
include/deps/msvc/sys
include/features
include/opencv
include/opencv2/imgproc
include/opencv2/core
include/opencv2/ml
include/opencv2
include/prediction
include)
file(GLOB_RECURSE SOURCES
"src/features/*.cpp"
"src/opencv/core/*.cpp"
"src/opencv/core/*.hpp"
"src/opencv/imgproc/*.cpp"
"src/opencv/imgproc/*.h"
"src/opencv/ml/*.cpp"
"src/opencv/ml/*.hpp"
"src/prediction/*.cpp"
"src/*.cpp"
"src/*.c")
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).
native-lib.cpp
${SOURCES})
find_library( # Sets the name of the path variable.
log-lib
log)
find_package(ZLIB)
target_link_libraries( # Specifies the target library.
native-lib
${log-lib}
${ZLIB_LIBRARIES})
Also check my gradle cmake declare.
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
arguments '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_STL=gnustl_static',
'-DANDROID_CPP_FEATURES=exceptions rtti',
'-DLOCAL_ALLOW_UNDEFINED_SYMBOLS = true'
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
I have try many solutions and also try used latest NDK r20 but still getting this error. How can I solved this error?
It's a compiler-specific thing.
As much as I'm aware most compilers would use va_list.

Android Studio CMakeLists error: undefined reference to

I have this project
I am tring to build C's sources with CMakeLists :
# 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.
rtmp-jni
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${CMAKE_SOURCE_DIR}/src/main/cpp/rtmp-jni.c)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../jnisource"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/includes"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/includes/openssl"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/librtmp")
# 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.
rtmp-jni
# Links the target library to the log library
# included in the NDK.
${log-lib} )
When i build my APK, i have this error :
Build command failed.
Error while executing process /Users/kevinabrioux/android-sdks/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target rtmp-jni}
[1/1] Linking C shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/librtmp-jni.so
FAILED: : && /Users/kevinabrioux/android-sdks/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=armv7-none-linux-androideabi --gcc-toolchain=/Users/kevinabrioux/android-sdks/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/kevinabrioux/android-sdks/ndk-bundle/sysroot -fPIC -isystem /Users/kevinabrioux/android-sdks/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot /Users/kevinabrioux/android-sdks/ndk-bundle/platforms/android-21/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,librtmp-jni.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/librtmp-jni.so CMakeFiles/rtmp-jni.dir/src/main/cpp/rtmp-jni.c.o -llog -lm && :
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:14: error: undefined reference to 'RTMP_Alloc'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:20: error: undefined reference to 'RTMP_Init'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:21: error: undefined reference to 'RTMP_SetupURL'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:26: error: undefined reference to 'RTMP_Connect'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:26: error: undefined reference to 'RTMP_ConnectStream'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:35: error: undefined reference to 'RTMP_Close'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:36: error: undefined reference to 'RTMP_Free'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:54: error: undefined reference to 'RTMP_Read'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:75: error: undefined reference to 'RTMP_Pause'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:84: error: undefined reference to 'RTMP_IsConnected'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:93: error: undefined reference to 'RTMP_IsTimedout'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:99: error: undefined reference to 'RTMP_Close'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:100: error: undefined reference to 'RTMP_Free'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
What can i do to make my project to find reference on these objects ?
Your target_link_libraries must include librtmp. You don't need to build it as part of your project. It's perfectly Ok to make it once using the make files that come with this library, and reference it as IMPORTED, like
add_library(shared-lib SHARED IMPORTED)
set_target_properties(shared-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/librtmp/lib/${ANDROID_ABI}/librtmp.so)

NDK Clang error: undefined reference to 'localeconv'

I am trying to build C++ NDK lib inside Android Studio.I have an external lib called json and the Clang compiler faild on localeconv.
json.hpp:11867: error: undefined reference to 'localeconv'
The locale.h header exists and located inside ndk dir sysroot/usr/include.
My toolchain looks like this:
Gradle: (Showing only the part relevant to NDK)
externalNativeBuild {
cmake {
arguments "-DANDROID_PLATFORM_LEVEL=${platformVersion}",
'-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
}
ndk {
abiFilters 'armeabi-v7a'
}
}
Cmake
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -frtti -fexceptions -Wall")
//'native-lib' is the final .so that's packaged into apk
target_link_libraries(native-lib
OPENAL
FREETYPE
android
EGL
${OPENGL_LIB}
log
m
z
atomic
gnustl_static
)
And here is the linker command line:
[1/1] Linking CXX shared library
........\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . &&
D:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe
--target=armv7-none-linux-androideabi --gcc-toolchain=D:/Android/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64
--sysroot=D:/Android/android-sdk/ndk-bundle/sysroot -fPIC -isystem D:/Android/android-sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=19 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -Wall -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot D:/Android/android-sdk/ndk-bundle/platforms/android-19/arch-arm
-Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so
The complete error:
"D:/Android/android-sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a"
&& cd ." D:\XXXXX\XXXXXX\windows....\thirdparty\json/json.hpp:11867:
error: undefined reference to 'localeconv' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed. :app:externalNativeBuildDebug
FAILED
The target SDK is 21.Minimum SDK is 19.NDK Version: 15.0.4075724
The same code base is compiled fine in Visual Studio Android project which uses the same toolchain.
The answer is - NDK version for SDK 19 doesn't implement the whole C++11 standard in the STL. locale.h header has stubs for localeconv() method, but the library doesn't implement it.The closest Android SDK that implement localeconv() is SDK 21.This is implicitly stated in the header <locale.h>
struct lconv* localeconv(void) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
#if __ANDROID_API__ >= 21
locale_t duplocale(locale_t) __INTRODUCED_IN(21);
void freelocale(locale_t) __INTRODUCED_IN(21);
locale_t newlocale(int, const char*, locale_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */
char* setlocale(int, const char*);
#if __ANDROID_API__ >= 21
locale_t uselocale(locale_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */
#define LC_GLOBAL_LOCALE __BIONIC_CAST(reinterpret_cast, locale_t, -1L)
__END_DECLS
#endif /* _LOCALE_H_ */
For me, trying to use Lua 5.4.0, I have to define the API level to 21
Cmake file as:
set(ANDROID_NATIVE_API_LEVEL 21)
I had a similar problem, and unfortunaletly changing API level couldn't work for me --I was working with an old tablet which runs API16. You can try Crystax NDK or you can write an ugly function that mimics the localeconv(). The latter had solved my problem since I was building Lua for Android Terminal Emulator for hobby.

Android NDK CMakeLists.txt: error: undefined reference to:

I've looked around but I've only been able to find solutions that use Android.mk and Application.mk. Am I right in thinking that by using CMakeLists.txt I don't need either of those files? This is my first venture into using the Android NDK.
I've based my CMakeLists.txt off of the SuperpoweredExample and I have called my library nativelib. It seems the .cpp file cannot pick up the references in the header file. Am I doing something wrong? It builds fine but it just throws these errors on compilation.
CMakeLists.txt:
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 it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
nativelib
# 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.
G:/Git/NDKTest/app/src/main/jni/nativelib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included 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 the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
nativelib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Below here is copy and pasted from the SuperpoweredExample
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
set(
PATH_TO_SUPERPOWERED
"C:/Users/j/Downloads/Superpowered/Superpowered"
)
message(${ANDROID_ABI})
file(GLOB CPP_FILES "*.cpp")
add_library(
SuperpoweredExample
SHARED
${CPP_FILES}
${PATH_TO_SUPERPOWERED}/AndroidIO/SuperpoweredAndroidAudioIO.cpp
)
include_directories(src/main/jni)
include_directories(${PATH_TO_SUPERPOWERED})
target_link_libraries(
SuperpoweredExample
log
android
OpenSLES
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
nativelib
)
Stacktrace:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing 'G:\sdk1\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build G:\Git\NDKTest\app\.externalNativeBuild\cmake\debug\x86 --target nativelib}
[1/2] Building CXX object CMakeFiles/nativelib.dir/nativelib.cpp.o
[2/2] Linking CXX shared library G:\Git\NDKTest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so
FAILED: cmd.exe /C "cd . && G:\sdk1\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target i686-none-linux-android -gcc-toolchain G:/sdk1/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=G:/sdk1/ndk-bundle/platforms/android-16/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fsigned-char -Inull -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnativelib.so -o G:\Git\NDKTest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so CMakeFiles/nativelib.dir/nativelib.cpp.o -llog -lm "G:/sdk1/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a" && cd ."
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:16: error: undefined reference to 'SuperpoweredRoll::SuperpoweredRoll(unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:17: error: undefined reference to 'SuperpoweredFilter::SuperpoweredFilter(SuperpoweredFilterType, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:18: error: undefined reference to 'SuperpoweredFlanger::SuperpoweredFlanger(unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:19: error: undefined reference to 'SuperpoweredRecorder::SuperpoweredRecorder(char const*, unsigned int, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:21: error: undefined reference to 'SuperpoweredAndroidAudioIO::SuperpoweredAndroidAudioIO(int, int, bool, bool, bool (*)(void*, short*, int, int), void*, int, int, int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:28: error: undefined reference to 'SuperpoweredRecorder::stop()'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:30: error: undefined reference to 'SuperpoweredRecorder::start(char const*)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:37: error: undefined reference to 'SuperpoweredRecorder::process(float*, float*, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:38: error: undefined reference to 'SuperpoweredFloatToShortInt(float*, short*, unsigned int, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:43: error: undefined reference to 'SuperpoweredAndroidAudioIO::~SuperpoweredAndroidAudioIO()'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:44: error: undefined reference to 'SuperpoweredRecorder::~SuperpoweredRecorder()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Changed name from native-lib to nativelib, same error.
I have a feeling the error is around the target_link_libraries() of CMakeLists.txt. I am trying to link my NativeLib code with the existing SuperpoweredExample code.
I think linking your "nativelib" happens before linking the Superpowered example, therefore your linker can't find the Superpowered parts used by "nativelib".

Categories

Resources