IL2CPP Android build with custom static libraries linked with GNU STL static library
I need to link my own static libraries (plugins written in C++) on Android with IL2CPP backend.
Everything seems to work right except linking GNU STL static library that my libraries depend on. It looks like il2cpp.exe is not aware of this dependency and I'm getting lot of errors like:
error: undefined reference to 'std::allocator<char>::allocator()'
I can fix this by adding explicit dependency on il2cpp.exe command line:
--additional-libraries="C:\android-ndk-r16b\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi\libgnustl_static.a"
However, is there any standard way how to make IL2CPP builder aware of this dependency? I looked everywhere but couldn't find anything. And I don't want to "hack" the build process in any way.
I use Unity 2018.4.8f1. I could upgrade to 2019.2 if it helps.
For reference, this is my Application.mk
:
APP_STL := gnustl_static
APP_CPPFLAGS += -std=c++11
NDK_TOOLCHAIN_VERSION := 4.9
APP_ABI := armeabi-v7a arm64-v8a x86
And Android.mk
:
LOCAL_PATH:= $(call my-dir)
SRC_PATH := $(LOCAL_PATH)/../../
include $(CLEAR_VARS)
LOCAL_MODULE := libtest
LOCAL_SRC_FILES := test.cpp
LOCAL_C_INCLUDES += $(SRC_PATH)
LOCAL_CPPFLAGS := -fvisibility=hidden -DSTATIC_BUILD
LOCAL_DISABLE_FORMAT_STRING_CHECKS=true
include $(BUILD_STATIC_LIBRARY)
Complete il2cpp command line:
D:\Unity\2018.4.8f1\Editor\Data\il2cpp/build/il2cpp.exe
--convert-to-cpp
--emit-null-checks
--enable-array-bounds-check
--dotnetprofile="unityaot"
--compile-cpp
--libil2cpp-static
--platform="Android"
--architecture="ARMv7"
--configuration="Release"
--outputpath="D:\[...]\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a\libil2cpp.so"
--cachedirectory="D:\[...]\Assets\..\Library\il2cpp_android_armeabi-v7a/il2cpp_cache"
--additional-include-directories="D:\Unity\2018.4.8f1\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\bdwgc/include"
--additional-include-directories="D:\Unity\2018.4.8f1\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\libil2cpp/include"
--additional-libraries="D:\[...]\Assets/Plugins/MFG/LibNat/Android/armeabi-v7a/libtest.a"
--tool-chain-path="C:/Android/android-ndk-r16b-windows-x86_64/android-ndk-r16b"
--map-file-parser="D:\Unity\2018.4.8f1\Editor\Data\Tools\MapFileParser\MapFileParser.exe"
--directory="D:\[...]\Temp\StagingArea\assets\bin\Data\Managed"
--generatedcppdir="D:\[...]\Temp\StagingArea\Il2Cpp\il2cppOutput"
Your answer
Follow this Question
Related Questions
Adding .NET STANDARD DLL to unity 0 Answers
Trying to use an external library in my Android project, but managed code stripping causes an error. 3 Answers
Drastically worse performance with IL2CPP compared to Mono on Android 1 Answer
android native library: Content is not allowed in prolog 0 Answers
5.2.1beta and p1 both crash at "vm/Class.cpp:1398" on Android il2cpp 0 Answers