Question

I'm getting "cannot locate symbol" errors to OpenGLESv2 functions when I launch my app.

02-28 12:49:43.443: E/art(1258): dlopen("/data/app-lib/com.xxx.xxx-2/libmy_ndk.so", RTLD_LAZY) failed: dlopen failed: cannot locate symbol "glGenRenderbuffers" referenced by "libmy_ndk.so"...

The library structure is as follows:

C++ Library compiled with toolchain -> libmy_ndk.so
JNI Code calls C++ Library -> libmy.so

If I put the OpenGL functions in the JNI code and discard the C++ library entirely, it works as expected. But for some reason it's not dynamically linking OpenGL at runtime if I'm using the prebuilt C++ shared library.

My make file looks like this:

include $(CLEAR_VARS)
LOCAL_CFLAGS := -std=gnu++11
LOCAL_MODULE := my_ndk
LOCAL_SRC_FILES := libmy_ndk.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS := -lGLESv2
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := my
LOCAL_CFLAGS := -std=gnu++11
LOCAL_SRC_FILES := ndk.cpp
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog -landroid -lz
LOCAL_SHARED_LIBRARIES := my_ndk
include $(BUILD_SHARED_LIBRARY)

I'm not getting any compile errors, and everything but the OpenGL functions work. I tried using LOCAL_LDLIBS := -lGLESv2 for both the prebuilt and shared libraries, and then changed it to LOCAL_EXPORT_LDLIBS as shown above, and no combination of those seem to work either.

SOLUTION:

The problem was the compilation of the C++ library with the toolchain. The libGLESv2.so it was initially linking against was not the same version that was loaded on the device, which was causing the conflict when loading.

No correct solution

OTHER TIPS

There are different folders for different architecture, There is a high possibility that you have not provided your Native Libraries for a specific architecture that you are currently debugging on.

enter image description here


Kindly copy your .so Libs in these folders aswell.
I hope this helps.

Edit:
Please add the feature as required from the list below in your Manifest.xml file :

<-- require OpenGL ES version 1.0 (default) -->
<uses-feature android:glEsVersion="0x00010000"/>

<-- require OpenGL ES version 1.1 -->
<uses-feature android:glEsVersion="0x00010001"/>

<-- require OpenGL ES version 2.0 -->
<uses-feature android:glEsVersion="0x00020000"/>

<-- require OpenGL ES version 3.0 -->
<uses-feature android:glEsVersion="0x00030000"/>

Dynamic Liner Library :
Please go through This link : NDK OpenGL undefined reference to glVertexPointer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top