libvalhalla cmake link static library Android

Directory pic:

enter image description here

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

Answer

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
# ...
)