The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL2 on Android using CMake built-in nvidia nsight tegra - S
Peter List
Guest

I'm attempting to build a simple SDL2 Android application with CMake's built-in Android support (uses nvidia tegra nsight for visual studio 2010)


I'm able to compile my libpemDemos.so project with SDL2 code this way for armabi-v7a


I also compiled libSDL2.so for armabi-v7a using ndk-build, and I'm able to reference it from my pemDemos.vcxproj


My linker step does includes this: -L"[path]/SDL2-2.0.3/libs/armeabi-v7a" "-lSDL2"


However, I'm getting a linker error when I try to add SDL_android_main.c to my build:


1>  pemDemos.dir/Debug/SDL_android_main.o: In function `Java_org_libsdl_app_SDLActivity_nativeInit(_JNIEnv*, _jclass*, _jobject*)':
1>  [path]\SDL2-2.0.3\src\main\android\SDL_android_main.c(23):  undefined reference to `SDL_Android_Init(_JNIEnv*, _jclass*)'
1>collect2.exe : error : ld returned 1 exit status


If I comment out the following one line then I can build my libpemDemos.so again:


SDL_Android_Init(env, cls);


However that of course fails when I try to run it.


I don't understand why the linker doesn't see `SDL_Android_Init(_JNIEnv*, _jclass*)'.  I have "-lSDL2", plus I even verified that libSDL2.so has SDL_Android_Init():


Quote:
readelf -Ws [path]\SDL2-2.0.3\libs\armeabi-v7a\libSDL2.so | grep SDL_Android_Init
   216: 0002f60d   332 FUNC    GLOBAL DEFAULT    8 SDL_Android_Init


thank you for any leads
SDL2 on Android using CMake built-in nvidia nsight tegra - S
Peter List
Guest

I worked around that error by editing SDL_android_main.c:


extern "C"
{
/* Called before SDL_main() to initialize JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
}


So I'm at least able to build again now...  Though it still crashes when I try to run the APK...




On Tue, Aug 25, 2015 at 12:48 AM, Peter List wrote:
Quote:
I'm attempting to build a simple SDL2 Android application with CMake's built-in Android support (uses nvidia tegra nsight for visual studio 2010)


I'm able to compile my libpemDemos.so project with SDL2 code this way for armabi-v7a


I also compiled libSDL2.so for armabi-v7a using ndk-build, and I'm able to reference it from my pemDemos.vcxproj


My linker step does includes this: -L"[path]/SDL2-2.0.3/libs/armeabi-v7a" "-lSDL2"


However, I'm getting a linker error when I try to add SDL_android_main.c to my build:


1>  pemDemos.dir/Debug/SDL_android_main.o: In function `Java_org_libsdl_app_SDLActivity_nativeInit(_JNIEnv*, _jclass*, _jobject*)':
1>  [path]\SDL2-2.0.3\src\main\android\SDL_android_main.c(23):  undefined reference to `SDL_Android_Init(_JNIEnv*, _jclass*)'
1>collect2.exe : error : ld returned 1 exit status


If I comment out the following one line then I can build my libpemDemos.so again:


SDL_Android_Init(env, cls);


However that of course fails when I try to run it.


I don't understand why the linker doesn't see `SDL_Android_Init(_JNIEnv*, _jclass*)'.  I have "-lSDL2", plus I even verified that libSDL2.so has SDL_Android_Init():


Quote:
readelf -Ws [path]\SDL2-2.0.3\libs\armeabi-v7a\libSDL2.so | grep SDL_Android_Init
   216: 0002f60d   332 FUNC    GLOBAL DEFAULT    8 SDL_Android_Init


thank you for any leads



SDL2 on Android using CMake built-in nvidia nsight tegra - S
Peter List
Guest

I found a second change required to get hello world SDL2-2.0.3 working on Android with cmake + nvidia tegra nsight for visual studio 2010.  This second issue I found with adb logcat:

W/dalvikvm( 5954): No implementation found for native Lorg/libsdl/app/SDLActivity;.nativeInit:()V
W/dalvikvm( 5954): threadid=11: thread exiting with uncaught exception (group=0x418d2c80)
E/AndroidRuntime( 5954): FATAL EXCEPTION: SDLThread
E/AndroidRuntime( 5954): Process: org.libsdl.app, PID: 5954
E/AndroidRuntime( 5954): java.lang.UnsatisfiedLinkError: Native method not found: org.libsdl.app.SDLActivity.nativeInit:()V
E/AndroidRuntime( 5954):        at org.libsdl.app.SDLActivity.nativeInit(Native Method)
E/AndroidRuntime( 5954):        at org.libsdl.app.SDLMain.run(SDLActivity.java:510)
E/AndroidRuntime( 5954):        at java.lang.Thread.run(Thread.java:841)
I/AndroidRuntime( 5954): To Report FATAL to activityManagerService


The fix:


extern "C" // required to avoid build link error
{
/* Called before SDL_main() to initialize JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);


// required to avoid run found with adb logcat
extern void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj);
}


I hope this helps someone.  Also, I think this change should be included in the next code release of SDL2?










On Tue, Aug 25, 2015 at 1:10 AM, Peter List wrote:
Quote:
I worked around that error by editing SDL_android_main.c:


extern "C"
{
/* Called before SDL_main() to initialize JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
}


So I'm at least able to build again now...  Though it still crashes when I try to run the APK...




On Tue, Aug 25, 2015 at 12:48 AM, Peter List wrote:
Quote:
I'm attempting to build a simple SDL2 Android application with CMake's built-in Android support (uses nvidia tegra nsight for visual studio 2010)


I'm able to compile my libpemDemos.so project with SDL2 code this way for armabi-v7a


I also compiled libSDL2.so for armabi-v7a using ndk-build, and I'm able to reference it from my pemDemos.vcxproj


My linker step does includes this: -L"[path]/SDL2-2.0.3/libs/armeabi-v7a" "-lSDL2"


However, I'm getting a linker error when I try to add SDL_android_main.c to my build:


1>  pemDemos.dir/Debug/SDL_android_main.o: In function `Java_org_libsdl_app_SDLActivity_nativeInit(_JNIEnv*, _jclass*, _jobject*)':
1>  [path]\SDL2-2.0.3\src\main\android\SDL_android_main.c(23):  undefined reference to `SDL_Android_Init(_JNIEnv*, _jclass*)'
1>collect2.exe : error : ld returned 1 exit status


If I comment out the following one line then I can build my libpemDemos.so again:


SDL_Android_Init(env, cls);


However that of course fails when I try to run it.


I don't understand why the linker doesn't see `SDL_Android_Init(_JNIEnv*, _jclass*)'.  I have "-lSDL2", plus I even verified that libSDL2.so has SDL_Android_Init():


Quote:
readelf -Ws [path]\SDL2-2.0.3\libs\armeabi-v7a\libSDL2.so | grep SDL_Android_Init
   216: 0002f60d   332 FUNC    GLOBAL DEFAULT    8 SDL_Android_Init


thank you for any leads








SDL2 on Android using CMake built-in nvidia nsight tegra - S
Martin Gerhardy
Guest

If you have the unresolved symbol and are linking statically, then you most likely miss this: https://github.com/mgerhardy/caveexpress/blob/master/src/libs/sdl2/CMakeLists.txt#L164

Am 25.08.2015 um 16:57 schrieb Peter List:

Quote:
I found a second change required to get hello world SDL2-2.0.3 working on Android with cmake + nvidia tegra nsight for visual studio 2010.  This second issue I found with adb logcat:

W/dalvikvm( 5954): No implementation found for native Lorg/libsdl/app/SDLActivity;.nativeInit:()V
W/dalvikvm( 5954): threadid=11: thread exiting with uncaught exception (group=0x418d2c80)
E/AndroidRuntime( 5954): FATAL EXCEPTION: SDLThread
E/AndroidRuntime( 5954): Process: org.libsdl.app, PID: 5954
E/AndroidRuntime( 5954): java.lang.UnsatisfiedLinkError: Native method not found: org.libsdl.app.SDLActivity.nativeInit:()V
E/AndroidRuntime( 5954):        at org.libsdl.app.SDLActivity.nativeInit(Native Method)
E/AndroidRuntime( 5954):        at org.libsdl.app.SDLMain.run(SDLActivity.java:510)
E/AndroidRuntime( 5954):        at java.lang.Thread.run(Thread.java:841)
I/AndroidRuntime( 5954): To Report FATAL to activityManagerService


The fix:


extern "C" // required to avoid build link error
{
/* Called before SDL_main() to initialize JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);


// required to avoid run found with adb logcat
extern void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj);
}


I hope this helps someone.  Also, I think this change should be included in the next code release of SDL2?










On Tue, Aug 25, 2015 at 1:10 AM, Peter List wrote:
Quote:
I worked around that error by editing SDL_android_main.c:


extern "C"
{
/* Called before SDL_main() to initialize JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
}


So I'm at least able to build again now...  Though it still crashes when I try to run the APK...




On Tue, Aug 25, 2015 at 12:48 AM, Peter List wrote:
Quote:
I'm attempting to build a simple SDL2 Android application with CMake's built-in Android support (uses nvidia tegra nsight for visual studio 2010)


I'm able to compile my libpemDemos.so project with SDL2 code this way for armabi-v7a


I also compiled libSDL2.so for armabi-v7a using ndk-build, and I'm able to reference it from my pemDemos.vcxproj


My linker step does includes this: -L"[path]/SDL2-2.0.3/libs/armeabi-v7a" "-lSDL2"


However, I'm getting a linker error when I try to add SDL_android_main.c to my build:


1>  pemDemos.dir/Debug/SDL_android_main.o: In function `Java_org_libsdl_app_SDLActivity_nativeInit(_JNIEnv*, _jclass*, _jobject*)':
1>  [path]\SDL2-2.0.3\src\main\android\SDL_android_main.c(23):  undefined reference to `SDL_Android_Init(_JNIEnv*, _jclass*)'
1>collect2.exe : error : ld returned 1 exit status


If I comment out the following one line then I can build my libpemDemos.so again:


SDL_Android_Init(env, cls);


However that of course fails when I try to run it.


I don't understand why the linker doesn't see `SDL_Android_Init(_JNIEnv*, _jclass*)'.  I have "-lSDL2", plus I even verified that libSDL2.so has SDL_Android_Init():


Quote:
readelf -Ws [path]\SDL2-2.0.3\libs\armeabi-v7a\libSDL2.so | grep SDL_Android_Init
   216: 0002f60d   332 FUNC    GLOBAL DEFAULT    8 SDL_Android_Init


thank you for any leads













Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
--
--

http://www.caveproductions.org
http://www.ufoai.org