I use a dummy app to compile static libraries without needing to compile a (meaningful) shared library. This is a common practice to workaround the poor NDK build tools? limitations. The dummy app is simply one file with one line to make it valid C++:
#include <jni.h>
I am getting undefined reference to SDL_main when linking my (extremely simple) dummy app against SDL2.
NDK_TOOLCHAIN_VERSION=?clang3.1? ndk-build V=1 -B NDK_DEBUG=1
<lots of successful compiling deleted, then>
/Applications/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/…/…/…/…/arm-linux-androideabi/bin/ld: /src/android/obj/local/armeabi/libSDL2.a(SDL_android_main.o): in function Java_org_libsdl_app_SDLActivity_nativeInit:/vendors/SDL2/src/main/android/SDL_android_main.c:30: error: undefined reference to ‘SDL_main’
This goes away if I remove "-Wl,–undefined=Java_org_libsdl_app_SDLActivity_nativeInit? from this line of SDL2/Android.mk:
LOCAL_EXPORT_LDLIBS := -Wl,–undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
This command forces my dummy project to throw a linker error for undefined symbol, forcing my linking shared library to define it. I believe this means I need to include an SDL_main in my dummy project to compile the library.
extern “C” int SDL_main(int argc, char *argv[])
{
// A dummy main that is necessary to compile SDL2 statically.
return 0;
}
If I have this correct, I would like to propose a small change to the README-Android.txt. Please let me know if I have run afoul of best practices here before I suggest an addition to the readme.
Michael Labb?
No responses, but not to worry. I should have seen that SDL_android_main.c had to be manually added.
One suggested change to the README-Android.txt file:
The Java code loads your game code, the SDL shared library, and
dispatches to native functions implemented in the SDL library:
-src/SDL_android.c
+src/core/android/SDL_android.c
Michael Labb?On Dec 5, 2013, at 7:07 PM, Michael Labb? <@Michael_Labbe> wrote:
I use a dummy app to compile static libraries without needing to compile a (meaningful) shared library. This is a common practice to workaround the poor NDK build tools? limitations. The dummy app is simply one file with one line to make it valid C++:
#include <jni.h>
I am getting undefined reference to SDL_main when linking my (extremely simple) dummy app against SDL2.
NDK_TOOLCHAIN_VERSION=?clang3.1? ndk-build V=1 -B NDK_DEBUG=1
<lots of successful compiling deleted, then>
/Applications/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/…/…/…/…/arm-linux-androideabi/bin/ld: /src/android/obj/local/armeabi/libSDL2.a(SDL_android_main.o): in function Java_org_libsdl_app_SDLActivity_nativeInit:/vendors/SDL2/src/main/android/SDL_android_main.c:30: error: undefined reference to ‘SDL_main’
This goes away if I remove "-Wl,–undefined=Java_org_libsdl_app_SDLActivity_nativeInit? from this line of SDL2/Android.mk:
LOCAL_EXPORT_LDLIBS := -Wl,–undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
This command forces my dummy project to throw a linker error for undefined symbol, forcing my linking shared library to define it. I believe this means I need to include an SDL_main in my dummy project to compile the library.
extern “C” int SDL_main(int argc, char *argv[])
{
// A dummy main that is necessary to compile SDL2 statically.
return 0;
}
If I have this correct, I would like to propose a small change to the README-Android.txt. Please let me know if I have run afoul of best practices here before I suggest an addition to the readme.
Michael Labb?