Integrating FFMPEG using cmake: undefined reference when linking libraries - android

I've been trying to cross-compile ffmpeg for different Android cpu archs for couple of days now and I have finally succeeded in the task. But now that I need to integrate these pre-built .so files in my project I'm facing errors which have me baffled.
This is the CMakeLists.txt which I'm using:
cmake_minimum_required(VERSION 3.4.1)
# convert SDK path to forward slashes on Windows
file(TO_CMAKE_PATH ${PATH_TO_SUPERPOWERED} PATH_TO_SUPERPOWERED)
set(CMAKE_VERBOSE_MAKEFILE on)
include_directories(src/main/cpp)
include_directories(${PATH_TO_SUPERPOWERED})
include_directories(${PATH_TO_FFMPEG}/${ANDROID_ABI}/include)
add_library(
avutil
SHARED
${PATH_TO_FFMPEG}/${ANDROID_ABI}/lib/libavutil.so
)
set_target_properties(avutil PROPERTIES LINKER_LANGUAGE CXX)
add_library(
avformat
SHARED
${PATH_TO_FFMPEG}/${ANDROID_ABI}/lib/libavformat.so
)
set_target_properties(avformat PROPERTIES LINKER_LANGUAGE CXX)
add_library(
avcodec
SHARED
${PATH_TO_FFMPEG}/${ANDROID_ABI}/lib/libavcodec.so
)
set_target_properties(avcodec PROPERTIES LINKER_LANGUAGE CXX)
add_library(
Canto
SHARED
src/main/cpp/Dubsmash.cpp
src/main/cpp/Karaoke.cpp
src/main/cpp/Singing.cpp
src/main/cpp/EditDubsmash.cpp
${PATH_TO_SUPERPOWERED}/AndroidIO/SuperpoweredAndroidAudioIO.cpp
)
# link the native library against the following libraries
target_link_libraries(
Canto
avutil
avformat
avcodec
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
OpenSLES
log
android
)
And this is the source of the file I'm getting errors on:
#include <jni.h>
#include <android/log.h>
#include <string>
// unrelated includes
#include <libavformat/avformat.h>
#include <libavutil/dict.h>
#define log_write __android_log_write
#define log_print __android_log_print
// unrelated code parts
int print_file_data(const char *filePath) {
AVFormatContext *fmt_ctx = NULL;
AVDictionaryEntry *tag = NULL;
int ret;
if ((ret = avformat_open_input(&fmt_ctx, filePath, NULL, NULL)))
return ret;
while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
log_print(ANDROID_LOG_DEBUG, "%s=%s\n", tag->key, tag->value);
avformat_close_input(&fmt_ctx);
return 0;
}
And finally the errors themselves:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /home/hamed/dev/android-tools/android-sdk-linux/cmake/3.6.4111459/bin/cmake with arguments {--build /home/hamed/dev/projects/canto/Canto/app/.externalNativeBuild/cmake/debug/x86 --target Canto}
[1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86/libCanto.so
FAILED: : && /home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=i686-none-linux-android16 --gcc-toolchain=/home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/sysroot -fPIC -isystem /home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/sysroot/usr/include/i686-linux-android -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -fsigned-char -I/home/hamed/dev/projects/canto/Canto/app/../Superpowered -I/home/hamed/dev/projects/canto/Canto/app/../ffmpeg -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/platforms/android-16/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libCanto.so -o ../../../../build/intermediates/cmake/debug/obj/x86/libCanto.so CMakeFiles/Canto.dir/src/main/cpp/Dubsmash.cpp.o CMakeFiles/Canto.dir/src/main/cpp/Karaoke.cpp.o CMakeFiles/Canto.dir/src/main/cpp/Singing.cpp.o CMakeFiles/Canto.dir/src/main/cpp/EditDubsmash.cpp.o CMakeFiles/Canto.dir/home/hamed/dev/projects/canto/Canto/Superpowered/AndroidIO/SuperpoweredAndroidAudioIO.cpp.o ../../../../build/intermediates/cmake/debug/obj/x86/libavutil.so ../../../../build/intermediates/cmake/debug/obj/x86/libavformat.so ../../../../../Superpowered/libSuperpoweredAndroidx86.a -lOpenSLES -llog -landroid -latomic -lm "/home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++_static.a" "/home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++abi.a" "/home/hamed/dev/android-tools/android-sdk-linux/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libandroid_support.a" && :
/home/hamed/dev/projects/canto/Canto/app/src/main/cpp/Dubsmash.cpp:295: error: undefined reference to 'avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)'
/home/hamed/dev/projects/canto/Canto/app/src/main/cpp/Dubsmash.cpp:298: error: undefined reference to 'av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/home/hamed/dev/projects/canto/Canto/app/src/main/cpp/Dubsmash.cpp:301: error: undefined reference to 'avformat_close_input(AVFormatContext**)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Obviously the linker can not find the needed libraries, but why?!
UPDATE
This is the result of running nm on libavutil.so:
0000000000000510 t atexit
0000000000000500 t __atexit_handler_wrapper
0000000000002008 A __bss_start
U __cxa_atexit
U __cxa_finalize
0000000000002000 d __dso_handle
0000000000001dd8 d _DYNAMIC
0000000000002008 A _edata
00000000000004e0 t __emutls_unregister_key
0000000000002008 A _end
00000000000005e8 r __FRAME_END__
0000000000001fd8 d _GLOBAL_OFFSET_TABLE_
0000000000000258 r ndk_build_number
0000000000000218 r ndk_version
0000000000000200 r note_android_ident
0000000000000214 r note_data
0000000000000298 r note_end
000000000000020c r note_name
00000000000004d0 t __on_dlclose
00000000000004f0 t __on_dlclose_late
and on libavformat:
0000000000000520 t atexit
0000000000000510 t __atexit_handler_wrapper
0000000000002008 A __bss_start
U __cxa_atexit
U __cxa_finalize
0000000000002000 d __dso_handle
0000000000001dd8 d _DYNAMIC
0000000000002008 A _edata
00000000000004f0 t __emutls_unregister_key
0000000000002008 A _end
00000000000005f8 r __FRAME_END__
0000000000001fd8 d _GLOBAL_OFFSET_TABLE_
0000000000000258 r ndk_build_number
0000000000000218 r ndk_version
0000000000000200 r note_android_ident
0000000000000214 r note_data
0000000000000298 r note_end
000000000000020c r note_name
00000000000004e0 t __on_dlclose
0000000000000500 t __on_dlclose_late
UPDATE 2
I applied #szatmary suggestion and finally managed to to build the apk file but upon reaching the System.loadLibrary call an exception occurs indicating that the linker can not find libavutil.so.56. I tried changing the address of the library in the cmake file to actually contain the version numbered lib file to no avail:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libavutil.so.56" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1657)
at com.hmomeni.canto.activities.EditActivity.<init>(EditActivity.kt:26)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

ffmpeg is written in C, It links different than C++ due to name mangling.
remove the set_target_properties LINKER_LANGUAGE CXX stuff
set_target_properties(avcodec PROPERTIES LINKER_LANGUAGE CXX)
and wrap the lib includes
extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/dict.h>
}

Related

libvalhalla cmake link static library Android

Directory pic:
This is how I compile protobuf:
export NDK=~/Android/Sdk/ndk/23.1.7779620
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=x86_64-linux-android
export API=26
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
export LDFLAGS="-llog -fPIC"
export CXXFLAGS="-fPIC"
../protobuf-3.19.0/configure --host $TARGET --disable-shared --with-pic
make -j$(nproc)
This is how I compile valhalla:
export PROTOBUF_INSTALL_DIR=/opt/protobuf
export PROTOBUF_HEADERS=$PROTOBUF_INSTALL_DIR/include
export PROTOC=$PROTOBUF_INSTALL_DIR/bin/protoc
export PROTOBUF_LIB=../protobuf_android/src/.libs # static libs that got generated from previous build script
export NDK=~/Android/Sdk/ndk/23.1.7779620
export TOOLCHAIN=$NDK/build/cmake/android.toolchain.cmake
cmake ../valhalla \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_PLATFORM="android-26" \
-DANDROID_ABI="x86_64" \
-DANDROID_NDK="$NDK" \
-DANDROID_TOOLCHAIN=clang++ \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
-DENABLE_PYTHON_BINDINGS=Off \
-DProtobuf_PROTOC_EXECUTABLE=$PROTOC \
-DProtobuf_INCLUDE_DIR=$PROTOBUF_HEADERS \
-DProtobuf_LIBRARY_RELEASE=$PROTOBUF_LIB \
-DENABLE_TOOLS=Off \
-DENABLE_HTTP=Off \
-DENABLE_SERVICES=Off \
-DENABLE_DATA_TOOLS=Off \
-DENABLE_STATIC_LIBRARY_MODULES=On \
-DBUILD_SHARED_LIBS=Off \
-DBoost_INCLUDE_DIR=${HOME}/Documents/routing/boost-1.77.0/
make -j$(nproc)
And the CMakeLists.txt
cmake_minimum_required(VERSION 3.12.1)
project(react-native)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES native-lib.cpp)
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
set(ANDROID_ABI_LIBS ${CMAKE_SOURCE_DIR}/lib/${ANDROID_ABI})
include_directories(${INCLUDE_DIR})
# Add source files
add_library(react-native SHARED ${SOURCE_FILES})
# libvalhalla import
add_library(libvalhalla STATIC IMPORTED)
set_target_properties(libvalhalla PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla.a)
# valhalla-baldr
add_library(valhalla-baldr STATIC IMPORTED)
set_target_properties(valhalla-baldr PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/baldr/libvalhalla-baldr.a)
# valhalla-loki
add_library(valhalla-loki STATIC IMPORTED)
set_target_properties(valhalla-loki PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-loki.a)
# valhalla-meili
add_library(valhalla-meili STATIC IMPORTED)
set_target_properties(valhalla-meili PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-meili.a)
# valhalla-midgard
add_library(valhalla-midgard STATIC IMPORTED)
set_target_properties(valhalla-midgard PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-midgard.a)
# valhalla-odin
add_library(valhalla-odin STATIC IMPORTED)
set_target_properties(valhalla-odin PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-odin.a)
# valhalla-sif
add_library(valhalla-sif STATIC IMPORTED)
set_target_properties(valhalla-sif PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-sif.a)
# valhalla-skadi
add_library(valhalla-skadi STATIC IMPORTED)
set_target_properties(valhalla-skadi PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-skadi.a)
# valhalla-tyr
add_library(valhalla-tyr STATIC IMPORTED)
set_target_properties(valhalla-tyr PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-tyr.a)
# valhalla-thor
add_library(valhalla-thor STATIC IMPORTED)
set_target_properties(valhalla-thor PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-thor.a)
# libprotobuf
add_library(libprotobuf STATIC IMPORTED)
set_target_properties(libprotobuf PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libprotobuf.a)
# libvalhalla-proto
add_library(libvalhalla-proto STATIC IMPORTED)
set_target_properties(libvalhalla-proto PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI_LIBS}/libvalhalla-proto.a)
file(GLOB_RECURSE Foo_HEADERS CONFIGURE_DEPENDS "src/*.h")
set(Foo_INCLUDE_DIRS "")
foreach (_headerFile ${Foo_HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list(APPEND Foo_INCLUDE_DIRS ${_dir})
endforeach ()
list(REMOVE_DUPLICATES Foo_INCLUDE_DIRS)
target_include_directories(react-native PUBLIC
${ANDROID_ABI_LIBS}/valhalla
${ANDROID_ABI_LIBS}/valhalla/proto
${ANDROID_ABI_LIBS}/google/protobuf
${ANDROID_ABI_LIBS}/baldr
${Foo_INCLUDE_DIRS}
logger)
target_link_libraries(valhalla-tyr INTERFACE
valhalla-baldr
valhalla-loki
valhalla-thor
valhalla-odin
valhalla-proto)
target_link_libraries(valhalla-loki INTERFACE
valhalla-tyr)
find_library(log-lib log android)
target_link_libraries(react-native
-Wl,--start-group
libvalhalla
valhalla-baldr
valhalla-thor
valhalla-meili
valhalla-odin
valhalla-sif
valhalla-skadi
valhalla-tyr
valhalla-midgard
libprotobuf
libvalhalla-proto
-Wl,--end-group
log
${log-lib}
android)
Stackrace Android Studio:
Build command failed.
Error while executing process /usr/bin/ninja with arguments {-C app/.cxx/Release/231y4r2y/x86_64 react-native}
ninja: Entering directory `app/.cxx/Release/231y4r2y/x86_64'
[1/2] Building CXX object CMakeFiles/react-native.dir/native-lib.cpp.o
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: x86_64-none-linux-android26
Thread model: posix
InstalledDir: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x
Found candidate GCC installation: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x
Selected GCC installation: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x
Candidate multilib: .;#m64
Selected multilib: .;#m64
"~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" -cc1 -triple x86_64-none-linux-android26 -emit-obj -mnoexecstack -disable-free -disable-llvm-verifier -discard-value-names -main-file-name native-lib.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-feature +sse4.2 -target-feature +popcnt -target-feature +cx16 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -v -ffunction-sections -fdata-sections -coverage-notes-file app/.cxx/Release/231y4r2y/x86_64/CMakeFiles/react-native.dir/native-lib.cpp.gcno -resource-dir ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9 -dependency-file CMakeFiles/react-native.dir/native-lib.cpp.o.d -sys-header-deps -MT CMakeFiles/react-native.dir/native-lib.cpp.o -D react_native_EXPORTS -I app/src/main/cpp/include -D ANDROID -D _FORTIFY_SOURCE=2 -D NDEBUG -isysroot ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -internal-isystem ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1 -internal-isystem ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include -internal-isystem ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include -internal-externc-isystem ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/x86_64-linux-android -internal-externc-isystem ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include -internal-externc-isystem ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -O2 -Wformat -Werror=format-security -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir app/.cxx/Release/231y4r2y/x86_64 -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o CMakeFiles/react-native.dir/native-lib.cpp.o -x c++ app/src/main/cpp/native-lib.cpp
clang -cc1 version 9.0.9 based upon LLVM 9.0.9svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include"
#include "..." search starts here:
#include <...> search starts here:
app/src/main/cpp/include
~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1
~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include
~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include
~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/x86_64-linux-android
~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
End of search list.
[2/2] Linking CXX shared library app/build/intermediates/cxx/Release/231y4r2y/obj/x86_64/libreact-native.so
FAILED: app/build/intermediates/cxx/Release/231y4r2y/obj/x86_64/libreact-native.so
: && ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android26 --gcc-toolchain=~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-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 -std=c++17 -v -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,libreact-native.so -o app/build/intermediates/cxx/Release/231y4r2y/obj/x86_64/libreact-native.so CMakeFiles/react-native.dir/native-lib.cpp.o -Wl,--start-group app/src/main/cpp/lib/x86_64/libvalhalla.a app/src/main/cpp/lib/x86_64/libprotobuf.a app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a app/src/main/cpp/lib/x86_64/libvalhalla-thor.a app/src/main/cpp/lib/x86_64/libvalhalla-meili.a app/src/main/cpp/lib/x86_64/libvalhalla-odin.a app/src/main/cpp/lib/x86_64/libvalhalla-sif.a app/src/main/cpp/lib/x86_64/libvalhalla-skadi.a app/src/main/cpp/lib/x86_64/libvalhalla-tyr.a app/src/main/cpp/lib/x86_64/libvalhalla-midgard.a app/src/main/cpp/lib/x86_64/libvalhalla-proto.a -llog ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/26/liblog.so -landroid -Wl,--end-group app/src/main/cpp/lib/x86_64/libvalhalla-loki.a app/src/main/cpp/lib/x86_64/libvalhalla-tyr.a app/src/main/cpp/lib/x86_64/libvalhalla-loki.a app/src/main/cpp/lib/x86_64/libvalhalla-thor.a app/src/main/cpp/lib/x86_64/libvalhalla-odin.a app/src/main/cpp/lib/x86_64/libvalhalla-proto.a app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a -latomic -lm && :
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: x86_64-none-linux-android26
Thread model: posix
InstalledDir: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x
Found candidate GCC installation: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x
Selected GCC installation: ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x
Candidate multilib: .;#m64
Selected multilib: .;#m64
"~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld" --sysroot=~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -z noexecstack --warn-shared-textrel -z now -z relro --hash-style=gnu --enable-new-dtags --eh-frame-hdr -m elf_x86_64 -shared -o app/build/intermediates/cxx/Release/231y4r2y/obj/x86_64/libreact-native.so ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/26/crtbegin_so.o -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/x86_64 -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/lib/../lib64 -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/26 -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/lib -L~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib --exclude-libs libgcc.a --exclude-libs libgcc_real.a --exclude-libs libatomic.a --build-id --fatal-warnings --no-undefined -soname libreact-native.so CMakeFiles/react-native.dir/native-lib.cpp.o --start-group app/src/main/cpp/lib/x86_64/libvalhalla.a app/src/main/cpp/lib/x86_64/libprotobuf.a app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a app/src/main/cpp/lib/x86_64/libvalhalla-thor.a app/src/main/cpp/lib/x86_64/libvalhalla-meili.a app/src/main/cpp/lib/x86_64/libvalhalla-odin.a app/src/main/cpp/lib/x86_64/libvalhalla-sif.a app/src/main/cpp/lib/x86_64/libvalhalla-skadi.a app/src/main/cpp/lib/x86_64/libvalhalla-tyr.a app/src/main/cpp/lib/x86_64/libvalhalla-midgard.a app/src/main/cpp/lib/x86_64/libvalhalla-proto.a -llog ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/26/liblog.so -landroid --end-group app/src/main/cpp/lib/x86_64/libvalhalla-loki.a app/src/main/cpp/lib/x86_64/libvalhalla-tyr.a app/src/main/cpp/lib/x86_64/libvalhalla-loki.a app/src/main/cpp/lib/x86_64/libvalhalla-thor.a app/src/main/cpp/lib/x86_64/libvalhalla-odin.a app/src/main/cpp/lib/x86_64/libvalhalla-proto.a app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a -latomic -lm -Bstatic -lc++ -Bdynamic -lm -lgcc -ldl -lc -lgcc -ldl ~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/26/crtend_so.o
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::deflate(std::__ndk1::function<int (z_stream_s&)> const&, std::__ndk1::function<void (z_stream_s&)> const&, int, bool): error: undefined reference to 'deflateInit2_'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::deflate(std::__ndk1::function<int (z_stream_s&)> const&, std::__ndk1::function<void (z_stream_s&)> const&, int, bool): error: undefined reference to 'deflate'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::deflate(std::__ndk1::function<int (z_stream_s&)> const&, std::__ndk1::function<void (z_stream_s&)> const&, int, bool): error: undefined reference to 'deflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::deflate(std::__ndk1::function<int (z_stream_s&)> const&, std::__ndk1::function<void (z_stream_s&)> const&, int, bool): error: undefined reference to 'deflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::deflate(std::__ndk1::function<int (z_stream_s&)> const&, std::__ndk1::function<void (z_stream_s&)> const&, int, bool): error: undefined reference to 'deflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::deflate(std::__ndk1::function<int (z_stream_s&)> const&, std::__ndk1::function<void (z_stream_s&)> const&, int, bool): error: undefined reference to 'deflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::inflate(std::__ndk1::function<void (z_stream_s&)> const&, std::__ndk1::function<int (z_stream_s&)> const&): error: undefined reference to 'inflateInit2_'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::inflate(std::__ndk1::function<void (z_stream_s&)> const&, std::__ndk1::function<int (z_stream_s&)> const&): error: undefined reference to 'inflate'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::inflate(std::__ndk1::function<void (z_stream_s&)> const&, std::__ndk1::function<int (z_stream_s&)> const&): error: undefined reference to 'inflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::inflate(std::__ndk1::function<void (z_stream_s&)> const&, std::__ndk1::function<int (z_stream_s&)> const&): error: undefined reference to 'inflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::inflate(std::__ndk1::function<void (z_stream_s&)> const&, std::__ndk1::function<int (z_stream_s&)> const&): error: undefined reference to 'inflateEnd'
app/src/main/cpp/lib/x86_64/baldr/libvalhalla-baldr.a(compression_utils.cc.o):compression_utils.cc:function valhalla::baldr::inflate(std::__ndk1::function<void (z_stream_s&)> const&, std::__ndk1::function<int (z_stream_s&)> const&): error: undefined reference to 'inflateEnd'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I know it has to with linking dependencies but I don't know how to fix it, I've been trying to fix this for weeks now but with no success.
app/gradle.build
cmake {
arguments "-DCMAKE_BUILD_TYPE=Release"
cppFlags "-std=c++17", "-v"
abiFilters "x86_64"
}
Edit: Update stacktrace and CMakeLists.txt
From your build output it seems that some of the valhalla libraries depend on each other, and those dependencies are not reflected in your CMakeLists.txt. For example, the Tyr library seems to depend at least on the Baldr, Loki, Thor and Odin libraries (as can be seen from the names of the undefined symbols you get). To reflect this dependency you should add something like this to your CMakeLists.txt file:
target_link_libraries(valhalla-tyr PUBLIC
valhalla-baldr
valhalla-loki
valhalla-thor
valhalla-odin
)
If after applying this you get undefined symbols from other libraries you should also add similar dependencies for other Valhalla libraries.
As an effect of this, the linker will be passed a slightly different set of arguments, with some libraries possibly listed more than once or in a different order. This will help the linker find the missing symbols.
Another possible solution is to enclose Valhalla libraries within --start-group/--end-group arguments in your last target_link_libraries statement. This solution would be more compiler-dependent but if this CMakeLists file is only intended to be used for Android this might be fine:
target_link_libraries( react-native
-Wl,--start-group
libvalhalla
valhalla-baldr
# other valhalla libraries
-Wl,--end-group
# ...
)

Android NDK ImageDecoder functions requires build error

I'm trying to get byte data of png file for GLES texture.
I have my png file in app\source\main\assets.
Texture::Texture(const char *path) {
AAsset* asset = loadAsset(path);
AImageDecoder* decoder;
int result = AImageDecoder_createFromAAsset(asset, &decoder);
if(result != ANDROID_IMAGE_DECODER_SUCCESS){
__android_log_print(ANDROID_LOG_VERBOSE, "Android2", "Texture constructor create decode FAIL. path: &s", path);
}
const AImageDecoderHeaderInfo* info = AImageDecoder_getHeaderInfo(decoder);
this->width = AImageDecoderHeaderInfo_getWidth(info);
this->height = AImageDecoderHeaderInfo_getHeight(info);
size_t stride = AImageDecoder_getMinimumStride(decoder);
size_t size = height * stride;
void* pixels = malloc(size);
result = AImageDecoder_decodeImage(decoder, pixels, stride, size);
if(result != ANDROID_IMAGE_DECODER_SUCCESS){
__android_log_print(ANDROID_LOG_VERBOSE, "Android2", "Texture constructor decode image FAIL. path: &s", path);
}
//GLES create texture and bind data(pixels)
free(pixels);
AAsset_close(asset);
}
but I got following build errors:
Build command failed.
Error while executing process C:\Users\jaewo\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Users\jaewo\AndroidStudioProjects\ANdroid2\app\.cxx\cmake\debug\x86 native-lib}
ninja: Entering directory `C:\Users\jaewo\AndroidStudioProjects\ANdroid2\app\.cxx\cmake\debug\x86'
[1/2] Building CXX object CMakeFiles/native-lib.dir/Texture.cpp.o
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:20:122: warning: data argument not used by format string [-Wformat-extra-args]
__android_log_print(ANDROID_LOG_VERBOSE, "Android2", "Texture constructor create decode FAIL. path: &s", path);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:32:121: warning: data argument not used by format string [-Wformat-extra-args]
__android_log_print(ANDROID_LOG_VERBOSE, "Android2", "Texture constructor decode image FAIL. path: &s", path);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
2 warnings generated.
[2/2] Linking CXX shared library C:\Users\jaewo\AndroidStudioProjects\ANdroid2\app\build\intermediates\cmake\debug\obj\x86\libnative-lib.so
FAILED: C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/build/intermediates/cmake/debug/obj/x86/libnative-lib.so
cmd.exe /C "cd . && C:\Users\jaewo\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android30 --gcc-toolchain=C:/Users/jaewo/AppData/Local/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/jaewo/AppData/Local/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-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 -std=c++17 -O0 -fno-limit-debug-info -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,libnative-lib.so -o C:\Users\jaewo\AndroidStudioProjects\ANdroid2\app\build\intermediates\cmake\debug\obj\x86\libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o CMakeFiles/native-lib.dir/AssetManager.cpp.o CMakeFiles/native-lib.dir/Texture.cpp.o -llog -landroid -lGLESv3 box2d/libbox2d.a -latomic -lm && cd ."
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:18: error: undefined reference to 'AImageDecoder_createFromAAsset'
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:23: error: undefined reference to 'AImageDecoder_getHeaderInfo'
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:24: error: undefined reference to 'AImageDecoderHeaderInfo_getWidth'
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:25: error: undefined reference to 'AImageDecoderHeaderInfo_getHeight'
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:27: error: undefined reference to 'AImageDecoder_getMinimumStride'
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:30: error: undefined reference to 'AImageDecoder_decodeImage'
C:/Users/jaewo/AndroidStudioProjects/ANdroid2/app/src/main/cpp/Texture.cpp:35: error: undefined reference to 'AImageDecoder_delete'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
in app build.gradle file, I set minSDKVersion to 30.
I think I should link a library about ImageDecoder or do something in my CMakeLists.txt.
but I'm not sure.
target_link_libraries(
native-lib
log
android
GLESv3
box2d)
You need to link jnigraphics.
For example:
target_link_libraries(
native-lib
log
android
GLESv3
box2d
jnigraphics)
There's an example at the image-decoder sample project.

Android Vulkan linker command failed

I'm trying to use Vulkan on Android so I had installed android ndk. I saw that in Android Studio default native C++, Vulkan is included. But whenever I build I get the following error:
C:/Users/a18/AndroidStudioProjects/vulkanSMD/app/src/main/cpp/native-lib.cpp:34:
error: undefined reference to 'vkCreateInstance' clang++: error:
linker command failed with exit code 1 (use -v to see invocation)
I've tried including libvulkan.so and also tried dlopen("libvulkan.so", flags) but it is of no use.
I'm trying to get Vulkan working on android. The below code creates a vulkan instance.
#include <jni.h>
#include <string>
#include <vector>
#define VK_USE_PLATFORM_ANDROID_KHR 1
#include <vulkan/vulkan.h>
std::vector<const char *>extensions;
std::vector<const char *>layers;
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_vulkansmd_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
extensions = std::vector<const char *>({
"VK_EXT_debug_report",
"VK_KHR_surface",
});
layers = std::vector<const char *>({"VK_LAYER_LUNARG_standard_validation"});
VkInstanceCreateInfo createInfo = {};
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Vulkan is hard";
appInfo.applicationVersion = VK_VERSION_1_0;
appInfo.engineVersion = VK_VERSION_1_0;
appInfo.apiVersion = VK_VERSION_1_0 ;
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
createInfo.ppEnabledExtensionNames = extensions.data();
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledLayerNames = layers.data();
createInfo.enabledLayerCount = static_cast<uint32_t>(layers.size());
VkInstance instance;
vkCreateInstance(&createInfo, nullptr, &instance);
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
While building however I get the following error
Build command failed. Error while executing process
C:\Users\a18\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\cmake.exe
with arguments {--build
C:\Users\a18\AndroidStudioProjects\vulkanSMD\app.externalNativeBuild\cmake\debug\x86_64
--target native-lib} [1/2] Building CXX object CMakeFiles/native-lib.dir/native-lib.cpp.o [2/2] Linking CXX shared
library
C:\Users\a18\AndroidStudioProjects\vulkanSMD\app\build\intermediates\cmake\debug\obj\x86_64\libnative-lib.so
FAILED:
C:/Users/a18/AndroidStudioProjects/vulkanSMD/app/build/intermediates/cmake/debug/obj/x86_64/libnative-lib.so
cmd.exe /C "cd . &&
C:\Users\a18\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe
--target=x86_64-none-linux-android26 --gcc-toolchain=C:/Users/a18/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64
--sysroot=C:/Users/a18/AppData/Local/Android/Sdk/ndk-bundle/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 -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,libnative-lib.so -o C:\Users\a18\AndroidStudioProjects\vulkanSMD\app\build\intermediates\cmake\debug\obj\x86_64\libnative-lib.so
CMakeFiles/native-lib.dir/native-lib.cpp.o -llog -latomic -lm && cd
."
C:/Users/a18/AndroidStudioProjects/vulkanSMD/app/src/main/cpp/native-lib.cpp:34:
error: undefined reference to 'vkCreateInstance' clang++: error:
linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Using std::bad_function_call with LIBCPP_ABI_UNSTABLE

I am trying to build a native library in my Android Studio project that uses the std::bad_function_call function.
Here's the CMakeLists.txt file I use to build my native module:
cmake_minimum_required(VERSION 3.4.1)
include_directories(src/main/cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -D_LIBCPP_ABI_UNSTABLE")
add_library(
MyLib
SHARED
src/main/cpp/test.cpp
)
and my test.cpp contains the following code:
void SomeClass::SomeMethod() {
std::function<int()> f = nullptr;
try {
f();
} catch (const std::bad_function_call& e) {
}
}
with the corresponding build.gradle section:
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static", "-DANDROID_NDK_ROOT=${android.ndkDirectory}"
}
}
If I pass the _LIBCPP_ABI_UNSTABLE flag to the compiler I get a link error:
Execution failed for task ':runtime:externalNativeBuildRelease'.
> Build command failed.
Error while executing process C:\android-sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\work\android-runtime\test-app\runtime\.externalNativeBuild\cmake\release\armeabi-v7a --target MyLib}
[1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\release\obj\armeabi-v7a\libMyLib.so
FAILED: cmd.exe /C "cd . && C:\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi17 --gcc-toolchain=C:/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 -fPIC --sysroot C:/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -fno-rtti -D_LIBCPP_ABI_UNSTABLE -Oz -DNDEBUG -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libMyLib.so -o ..\..\..\..\build\intermediates\cmake\release\obj\armeabi-v7a\libMyLib.so CMakeFiles/MyLib.dir/src/main/cpp/test.cpp.o ../../../../src/main/libs/armeabi-v7a/abc.a -llog -latomic -lm && cd ."
C:/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1/functional:0: error: undefined reference to 'vtable for std::__ndk1::bad_function_call'
C:/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: the vtable symbol may be undefined because the class is missing its key function
C:/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1/functional:0: error: undefined reference to 'std::__ndk1::bad_function_call::~bad_function_call()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
If I remove the _LIBCPP_ABI_UNSTABLE flag:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
then the project compiles fine.
So my question is what would be the proper way to enable the libc++ unstable abi and use the bad_function_call method inside my native module?
Note: I am using Android NDK 19.

Building Boost Library for Android on OS X Mavericks

I'm having an issue with attempting to build boost library for android. I have the apple command line tools installed and I downloaded boost. I kept getting this error:
In file included from libs/thread/src/pthread/thread.cpp:9:
In file included from ./boost/thread/detail/config.hpp:11:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
./boost/config/posix_features.hpp:18:15: fatal error: 'unistd.h' file not found
# include <unistd.h>
^
1 error generated.
...failed gcc.compile.c++ bin.v2/libs/thread/build/gcc-android/release/link-static/runtime-link-static/threading-multi/pthread/thread.o...
gcc.compile.c++ bin.v2/libs/thread/build/gcc-android/release/link-static/runtime-link-static/threading-multi/pthread/once.o
"g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pedantic -Wno-unused-function --sysroot=/Users/mac/src/android/tc/sysroot -fPIC -O3 -Wextra -Wno-long-long -Wno-variadic-macros -Wunused-function -pedantic -DBOOST_ALL_NO_LIB=1 -DBOOST_ATOMIC_STATIC_LINK=1 -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o "bin.v2/libs/thread/build/gcc-android/release/link-static/runtime-link-static/threading-multi/pthread/once.o" "libs/thread/src/pthread/once.cpp"
In file included from libs/thread/src/pthread/once.cpp:6:
In file included from ./boost/thread/detail/config.hpp:11:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
./boost/config/posix_features.hpp:18:15: fatal error: 'unistd.h' file not found
# include <unistd.h>
^
1 error generated.
...failed gcc.compile.c++ bin.v2/libs/thread/build/gcc-android/release/link-static/runtime-link-static/threading-multi/pthread/once.o...
gcc.compile.c++ bin.v2/libs/thread/build/gcc-android/release/link-static/runtime-link-static/threading-multi/future.o
"g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pedantic -Wno-unused-function --sysroot=/Users/mac/src/android/tc/sysroot -fPIC -O3 -Wextra -Wno-long-long -Wno-variadic-macros -Wunused-function -pedantic -DBOOST_ALL_NO_LIB=1 -DBOOST_ATOMIC_STATIC_LINK=1 -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o "bin.v2/libs/thread/build/gcc-android/release/link-static/runtime-link-static/threading-multi/future.o" "libs/thread/src/future.cpp"
In file included from libs/thread/src/future.cpp:6:
In file included from ./boost/thread/detail/config.hpp:11:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
./boost/config/posix_features.hpp:18:15: fatal error: 'unistd.h' file not found
# include <unistd.h>
^
1 error generated.
I got the same when building Boost 1.55.0 on Maverick with MacOSX10.7.sdk. So I added -I/usr/include to cflags and cxxflags options in my compile command. It resolved this problem. My full command.
./b2 -d+2 toolset=clang cxxflags="-stdlib=libc++ -isysroot=$SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -I/usr/include" cflags="-stdlib=libc++ -isysroot=$SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -I/usr/include" --layout=system --build-type=minimal --prefix=$QTDIR link=static runtime-link=static variant=release install

Categories

Resources