3

I'm trying to wrap some functions of a c-library (OpenAL-MOB) in order to use them in my Android application.

I think that my functions aren't correctly exported.

Steps I've taken:

  1. I've made a java class with the functions I would like to use in my Android application,
  2. Created stubs by using javah and javac (I haven't changed any class names or package names after doing this),
  3. Added the wrapper files to the Android.mk
  4. Build an .so library (with ndk-build)
  5. Copied the .so file to the libs/armeabi-folder of my android project
  6. Loaded the library in my android code and called a native function -> unsatisfiedinkerror.

When I try to use the library in my android code, I am able to load the library, but it cannot find my wrapped functions.

System.loadLibrary("openal"); // Works
OpenAlConnector.init(); // My wrapped function throws an unsatisfiedlinkerror

I think that my functions aren't actually exported.

To add my wrapper functions, I've modified the Android.mk that was already present in the OpenAL-MOB project. I didn't get any errors during the build. The only thing I did, was adding 2 files (.c created by javah and a helper class) to the end of LOCAL_SRC_FILES.

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include $(LOCAL_PATH)/../../OpenAL32/Include   $(LOCAL_PATH)/../../mob/Include $(LOCAL_PATH) 
LOCAL_MODULE    := openal-static
LOCAL_SRC_FILES := ../../Alc/ALc.c ../../Alc/alcConfig.c ../../Alc/alcDedicated.c     ../../Alc/alcEcho.c ../../Alc/alcModulator.c ../../Alc/alcReverb.c ../../Alc/alcRing.c ../../Alc/alcThread.c ../../Alc/ALu.c ../../Alc/backends/loopback.c ../../Alc/backends/null.c ../../Alc/backends/opensl.c ../../Alc/backends/wave.c ../../Alc/bs2b.c ../../Alc/helpers.c ../../Alc/hrtf.c ../../Alc/mixer.c ../../Alc/mixer_c.c ../../Alc/mixer_inc.c ../../Alc/mixer_neon.c ../../Alc/mixer_sse.c ../../Alc/panning.c ../../mob/alConfigMob.c ../../OpenAL32/alAuxEffectSlot.c ../../OpenAL32/alBuffer.c ../../OpenAL32/alEffect.c ../../OpenAL32/alError.c ../../OpenAL32/alExtension.c ../../OpenAL32/alFilter.c ../../OpenAL32/alListener.c ../../OpenAL32/alSource.c ../../OpenAL32/alState.c ../../OpenAL32/alThunk.c openalwrapper.c org_vansina_openal_OpenAlConnector.c 

# set the platform flags
ifeq ($(APP_ABI),x86)
    LOCAL_CFLAGS += -D HAVE_SSE 
else
    LOCAL_CFLAGS += -D HAVE_NEON -mfloat-abi=softfp -mfpu=neon -marm
endif

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := openal
LOCAL_STATIC_LIBRARIES := openal-static

include $(BUILD_SHARED_LIBRARY)    

I've used NM to see which functions were exported (nm.exe -D libopenal.so). This was the result:

00002004 A __bss_start
         U __cxa_atexit
         U __cxa_finalize
00002004 A _edata
00002004 A _end

I'm not sure if I'm correct, but it seems that my functions are missing. Does anyone have an idea what I can do or check? Is there a problem in my .mk file?

I'm try to wrap this library for some days now and I'm getting quite desparate. Any help is very much appreciated!

Edit: I believe that it has something to do with building the library as a static first and then as a shared library. It seems that all the symbols get lost if I create a shared lib like that. Can someone give me additional info about this?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Dirk V.
  • 151
  • 1
  • 10
  • Show an example of the implementation of one of your wrapper functions, and the **actual** error messages which result from attempting to invoke it. Try adding a native method or two with no further dependencies as a test. – Chris Stratton Nov 03 '14 at 22:44
  • Chris, you could be right about the dependencies. When I tried to build it as a shared lib, I got several error messages. F.i. a missing dependency of OpenSLES. I'll first try to solve those and see if the symbols are exported in the shared lib. – Dirk V. Nov 05 '14 at 21:27

0 Answers0