Error Building SDL for Android on Windows

Hi everyone,

I’m new here, so it’s nice to meet you all.

I’m trying to build the Android version of SDL on Windows. I’ve followed
this video to help get the basics set up: (I get as far as 3mins in before
I get stuck)

When I run ndk-build I get the follow error :?? SDL_android_main.c:23:
error: undefined reference to ‘SDL_Android_Init’

Here’s the full verbose output

ndk-build V=1
[armeabi] Compile thumb? : main

2014-03-28 17:23 GMT-03:00 steve at coldbeamgames.com
:

Hi everyone,

I’m new here, so it’s nice to meet you all.

I’m trying to build the Android version of SDL on Windows. I’ve followed
this video to help get the basics set up: (I get as far as 3mins in before
I get stuck)

https://www.youtube.com/watch?v=5_we0KZqDlU

When I run ndk-build I get the follow error : SDL_android_main.c:23:
error: undefined reference to ‘SDL_Android_Init’

For some reason it’s skipping over the libSDL2.so build part…are you
using SDL2’s own android-project?

I would suggest testing with the build-scripts/androidbuild.sh script, but
that will only work on Linux. In theory it should be possible to build from
Windows, I just never tried it.–
Gabriel.

Hi Gabriel,

Ah, it’s my mistake, I’d copied the SDL source to jni/src instead of jni/
Now that’s correct, the SDL lib builds just fine.

However, I now get this error:

snip
[armeabi] Compile thumb : SDL2 <= SDL_test_md5.c
[armeabi] Compile thumb : SDL2 <= SDL_test_random.c
[armeabi] SharedLibrary : libSDL2.so
[armeabi] Install : libSDL2.so => libs/armeabi/libSDL2.so
[armeabi] Compile thumb : main <= SDL_android_main.c
[armeabi] Compile++ thumb: main <= main.cpp
[armeabi] StaticLibrary : libstdc++.a
[armeabi] SharedLibrary : libmain.so

H:/android-sdk/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/…/lib/gcc/arm-linux-androideabi/4.6/…/…/…/…/arm-linux-androideabi/bin/ld.exe: H:\SVN_Repository\android-project/obj/local/armeabi/objs/main/__/SDL/src/main/android/SDL_android_main.o: in function Java_org_libsdl_app_SDLActivity_nativeInit:H:\SVN_Repository\android-project/jni/src/…/SDL/src/main/android/SDL_android_main.c:32: error: undefined reference to 'SDL_main’
collect2: ld returned 1 exit status
make.exe: *** [H:\SVN_Repository\android-project/obj/local/armeabi/libmain.so] E
rror 1

Any ideas?

The linker is not finding your main() function (which SDL redefines to
SDL_main). Make sure that main.cpp has a main() function and that its
signature is exactly as SDL expects:
int main(int argc, char* argv[])

Jonny D

I just looked at the main.cpp from the video you linked. It does have a
non-conformant main() that has a ‘const’ specifier. My guess is that’s the
issue.

Jonny DOn Mon, Mar 31, 2014 at 11:28 AM, Jonathan Dearborn <@Jonathan_Dearborn>wrote:

The linker is not finding your main() function (which SDL redefines to
SDL_main). Make sure that main.cpp has a main() function and that its
signature is exactly as SDL expects:
int main(int argc, char* argv[])

Jonny D

Oh wow, thanks. That was the problem. Thank you so much!

All building fine now.