How to link with third-party .so libraries?

Put problems with the Android NDK in this forum.

How to link with third-party .so libraries?

Postby paulscode » Tue Jul 26, 2011 7:16 pm

Let me apologize in advance, since this is probably a very basic C question (I've been using Java for too many years), but what is the proper way to compile native code that is dependent on an external, pre-compiled native .so library (without compiling the sources for that library at the same time)?

I have included the headers for the required .so libraries at the top of my code, but when I run ndk-build, I'm still getting errors like this:
Code: Select all
/home/paul/workspace/mycore/obj/local/armeabi-v7a/objs-debug/core/src/api/vidext.o: In function `VidExt_Init':
/home/paul/workspace/mycore/jni/core/src/api/vidext.c:89: undefined reference to `SDL_InitSubSystem'
/home/paul/workspace/mycore/jni/core/src/api/vidext.c:91: undefined reference to `SDL_GetError'
/home/paul/workspace/mycore/obj/local/armeabi-v7a/objs-debug/core/src/api/vidext.o: In function `VidExt_Quit':
/home/paul/workspace/mycore/jni/core/src/api/vidext.c:112: undefined reference to `SDL_WasInit'
/home/paul/workspace/mycore/jni/core/src/api/vidext.c:115: undefined reference to `SDL_ShowCursor'
/home/paul/workspace/mycore/jni/core/src/api/vidext.c:116: undefined reference to `SDL_QuitSubSystem'


The obvious reason is because those references are in the header files as "externs", while their actual implementations are in the .C files which have been compiled separately into the .so library I'm trying to link with. For example in SDL.h:
Code: Select all
/** This function initializes specific SDL subsystems */
extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);

/** This function cleans up specific SDL subsystems */
extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);

(where the actual implementations of SDL_InitSubSystem and SDL_QuitSubSystem are in SDL.c)

So how do I tell the compiler "Hey, you know those extern functions I told you about? They are implemented inside the .so library, so quit looking for them in the .C files, OK?"

I've tried adding the following to my Android.mk, but no luck:
Code: Select all
LOCAL_SHARED_LIBRARIES := sdl-1.2 sdl_main sdl_mixer sdl_image

Code: Select all
LOCAL_LDLIBS += -L/home/paul/workspace/mupen64plus/project/obj/local/armeabi/libsdl-1.2.so \
   -L/home/paul/workspace/mupen64plus/project/obj/local/armeabi/libsdl_main.so \
   -L/home/paul/workspace/mupen64plus/project/obj/local/armeabi/libsdl_mixer.so \
   -L/home/paul/workspace/mupen64plus/project/obj/local/armeabi/libsdl_image.so


Anything obvious I'm missing here? Thanks in advance for the help!
paulscode
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Thu Nov 11, 2010 3:57 pm

Top

Re: How to link with third-party .so libraries?

Postby paulscode » Tue Jul 26, 2011 8:13 pm

As usual, I solved my own problem immediately after posting the question. :)

ANYWAY, for folks who might have the same problem, I was able to compile with the following settings in my Android.mk file:
Code: Select all
LOCAL_LDFLAGS += -L/home/paul/workspace/mupen64plus/project/obj/local/armeabi

Code: Select all
LOCAL_LDLIBS += -lsdl-1.2 -lsdl_main -lsdl_mixer -lsdl_image

The two settings I mentioned in my previous post were not necessary.
paulscode
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Thu Nov 11, 2010 3:57 pm

Top

Return to NDK Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest