Search code examples
androidc++android-studioandroid-ndkndk-build

'Undefined reference to...' error after switching APP_STL from gnustl_static to c++_shared


I faced a problem after changing my APP_STL to c++_shared. I have got a lot of errors like ' vtable for typename: error: undefined reference to method ' or ' error: undefined reference to method ' inside cpp-files of my shared library. However everything works fine when I am using APP_STL = gnustl_static

I tried to ignore this errors using LOCAL_ALLOW_UNDEFINED_SYMBOLS = true in my Android.mk but it gave me a runtime crash with the message 'dlopen failed: cannot locate symbol ... referenced by ...'. Here is a part of my Android.mk. All functions, which become undefined, are contained in allHeadersHere-files.

LOCAL_MODULE    := mySharedLib    

LOCAL_C_INCLUDES := allHeadersHere

LOCAL_CPPFLAGS    :=  -Wno-error=narrowing -D_DEBUG -std=c++11 -pthread -frtti -fexceptions -g -gdwarf-2 -DANDROID_WCHAR -DANDROID_GLES2    
LOCAL_STATIC_LIBRARIES := somelib

FILE_LIST := $(wildcard $(LOCAL_PATH)/*.c*)       
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)    

include $(BUILD_SHARED_LIBRARY)

Solution

  • So finally I resolved this issue. Maybe it will be useful for somebody. I had a static libraries for NDK-v15 in my project. And these libraries were built with toolchains which are not compatible with APP_STL=c++_shared. So I added the same libraries to the project but for NDK-v18. But I forgot to update cpp-files. As the result compiler tried to find implementation for methods which are deprecated in new static libraries but were still declared in old cpp-files