New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined reference to 'SDL_main' #124
Comments
Include SDL.h in the source file with your main(), it will do
#define main SDL_main
Or just rename it yourself.
…On Mon, 30 Nov 2020, 13:15 V, ***@***.***> wrote:
I have an application that already uses SDL, and compiles for Windows and
Linux.
I pulled the latest version of this project and, after reading the readme,
was able to compile one of the demo applications. I had to fix licenses and
gradle's java path.
However, i cannot compile my app, i always get his linker error:
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-Wl,-soname,libsdl_main.so -shared
./obj/local/armeabi-v7a/objs/sdl_main/sdl_main.o
./obj/local/armeabi-v7a/objs/sdl_main/SDL_android_main.o -lgcc
-Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -latomic
-Wl,--exclude-libs,libatomic.a ./obj/local/armeabi-v7a/libsdl-1.2.so
./obj/local/armeabi-v7a/libapplication.so -target
armv7-none-linux-androideabi16 -no-canonical-prefixes -Wl,--build-id
-nostdlib++ -Wl,--no-undefined -Wl,--fatal-warnings -llog -lc -lm -o
./obj/local/armeabi-v7a/libsdl_main.so
jni/../jni/sdl_main/sdl_main.c:138: error: undefined reference to
'SDL_main'
jni/../jni/sdl_main/sdl_main.c:58: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/SDL_android_main.cpp:37: error: undefined reference to
'SDL_main'
clang++: error: linker command failed with exit code 1 (use -v to see
invocation)
make: *** [/home/myuser/Android/Sdk/ndk/21.1.6352462/build/core/
build-binary.mk:725: obj/local/armeabi-v7a/libsdl_main.so] Error 1
make: *** Waiting for unfinished jobs....
[armeabi-v7a] Install : libsdl-1.2.so => libs/armeabi-v7a/libsdl-1.2.so
install -p ./obj/local/armeabi-v7a/libsdl-1.2.so ./libs/armeabi-v7a/
libsdl-1.2.so
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip
--strip-unneeded ./libs/armeabi-v7a/libsdl-1.2.so
I'm not sure if i'm missing some enviroment variables.
I've run
./changeAppSettings.sh
./project/jni/application/setEnvironment-x86_64.sh
but i have no LD_LIBRARY_PATH set, nor $CFLAGS or $LDFLAGS.
This is my system:
$ uname -a
Linux myhost-VirtualBox 4.15.0-123-generic #126~16.04.1-Ubuntu SMP Wed Oct
21 13:48:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"
$ javac -version
javac 1.8.0_275
(installed from openjdk-8-* packages)
$ /home/myuser/Android/Sdk/ndk/21.1.6352462/ndk-build -version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Help would be appreciated.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#124>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABF5QG722OR2GB4JXGQN43SSN5ETANCNFSM4UHNPF5A>
.
|
I had already done those, to no avail. At the moment i'm using
and also had
My main is
|
Maybe it's because of C++ name mangling?
Please try to add this line before your SDL_main function:
extern "C" int SDL_main(int argc, char* argv[]);
…On Mon, 30 Nov 2020, 17:25 V, ***@***.***> wrote:
I had already done those, to no avail.
At the moment i'm using
#include <SDL/SDL.h>
#define main SDL_main
and also had
int SDL_main(int argc, char* argv[])
{
main(argc,argv);
}
My main is int main(int argc, char* argv[]), the liking error is not
thrown by my app's code, but that may or may not be misleading.
jni/../jni/sdl_main/sdl_main.c:138: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/sdl_main.c:58: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/SDL_android_main.cpp:37: error: undefined reference to 'SDL_main'
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABF5QE62WJY2GVVDVBPLXDSSO2PJANCNFSM4UHNPF5A>
.
|
No, didn't help. This is the offending line:
And the resulting error:
Looking at sdl_main.c it does #include "SDL_main.h" and i assume "" will look into -I paths (although i thought it meant "same dir as file"), and i see a lot of I made the following changes to project/jni/application/myuser/AndroidAppSettings.cfg
But from what i can see, the LD flags only apply to
Also, i have these libs installed system-wide:
|
Your libapplication.so is empty, it should contain SDL_main and the rest of
your app compiled code.
Did you enable custom build script option in AndroidAppSettings.cfg? Are
you using AndroidBuild.sh script to compile your code? Build system builds
an empty libapplication.so then replaces it with your actual library before
linking, but it looks like you have it in the wrong place. It should be
libapplication-armeabi-v7a.so in the same directory as AndroidBuild.sh.
…On Mon, 30 Nov 2020, 19:24 V, ***@***.***> wrote:
No, didn't help.
This is the offending line:
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -v -Wl,-soname,libsdl_main.so -shared
./obj/local/armeabi-v7a/objs/sdl_main/sdl_main.o
./obj/local/armeabi-v7a/objs/sdl_main/SDL_android_main.o
-lgcc -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -latomic -Wl,--exclude-libs,libatomic.a
./obj/local/armeabi-v7a/libsdl-1.2.so
./obj/local/armeabi-v7a/libapplication.so
-target armv7-none-linux-androideabi16 -no-canonical-prefixes
-Wl,--build-id -nostdlib++ -Wl,--no-undefined -Wl,--fatal-warnings -llog -lc -lm
-o ./obj/local/armeabi-v7a/libsdl_main.so
Android (6317467 based on r365631c1) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project e0caee08e5f09b374a27a676d04978c81fcb1928) (based on LLVM 9.0.8svn)
Target: armv7-none-linux-android16
Thread model: posix
InstalledDir: /home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: /home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x
Selected GCC installation: /home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x
Candidate multilib: ***@***.***
Candidate multilib: ***@***.***=armv7-a
Candidate multilib: ***@***.******@***.***
Candidate multilib: .;
Selected multilib: ***@***.***=armv7-a
"/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld"
-z noexecstack -EL --warn-shared-textrel -z now -z relro -X --hash-style=gnu --hash-style=both --enable-new-dtags --eh-frame-hdr -m armelf_linux_eabi -shared
-o ./obj/local/armeabi-v7a/libsdl_main.so
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/16/crtbegin_so.o
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/lib/linux/arm
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/16
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/../lib
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/../../lib
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a
-L/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib
-soname libsdl_main.so
./obj/local/armeabi-v7a/objs/sdl_main/sdl_main.o
./obj/local/armeabi-v7a/objs/sdl_main/SDL_android_main.o
-lgcc --exclude-libs libgcc.a --exclude-libs libgcc_real.a -latomic --exclude-libs libatomic.a
./obj/local/armeabi-v7a/libsdl-1.2.so
./obj/local/armeabi-v7a/libapplication.so
--build-id --no-undefined --fatal-warnings -llog -lc -lm -lm -lgcc -ldl -lc -lgcc -ldl
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/16/crtend_so.o
And the resulting error:
jni/../jni/sdl_main/sdl_main.c:138: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/sdl_main.c:58: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/SDL_android_main.cpp:37: error: undefined reference to 'SDL_main'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Looking at sdl_main.c it does #include "SDL_main.h" and i assume "" will
look into -I paths (although i thought it meant "same dir as file"), and i
see a lot of -Ijni/../jni/sdl-1.2/include so it should be ok.
I made the following changes to
project/jni/application/myuser/AndroidAppSettings.cfg
# Specify architectures to compile, 'all' or 'y' to compile for all architectures.
# Available architectures: armeabi-v7a arm64-v8a x86 x86_64
MultiABI='all'
# Aditional CFLAGS for application
AppCflags='-Dmain=SDL_main -DBYPASS_PROTECTION'
# Aditional C++-specific compiler flags for application, added after AppCflags
AppCppflags=''
# Additional LDFLAGS for application
AppLdflags='-z defs'
But from what i can see, the LD flags only apply to libapplication.so.
The remaining .so files seem to have a lot of undefined symbols:
$ nm -C -u project/obj/local/armeabi-v7a/objs/sdl_main/sdl_main.o
U __aeabi_memclr
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr1
U __android_log_print
U chdir
U exit
U malloc
U SDL_ANDROID_JavaVM
U SDL_ANDROID_MultiThreadedVideoLoop
U SDL_ANDROID_MultiThreadedVideoLoopInit
U SDL_CreateThread
U SDL_main
U setenv
U __stack_chk_fail
U __stack_chk_guard
U strchr
U strcpy
U strdup
U strlen
$ nm -C -u project/obj/local/armeabi-v7a/objs/sdl_main/SDL_android_main.o
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr1
U __android_log_print
U SDL_Android_Init
U SDL_main
U __stack_chk_fail
U __stack_chk_guard
U strdup
$ nm -C -u project/obj/local/armeabi-v7a/libsdl-1.2.so
U abort
U __aeabi_memclr
U __aeabi_memclr4
U __aeabi_memclr8
U __aeabi_memcpy
U __aeabi_memcpy4
U __aeabi_memmove4
U __aeabi_memset
U __android_log_print
U atoi
U calloc
U clock_gettime
U __cxa_atexit
U __cxa_finalize
U dladdr
U dlclose
U dlerror
U dlopen
U dlsym
U __errno
U fclose
U ferror
U fflush
U fmaxf
U fminf
U fopen
U fprintf
U fread
U free
U fseek
U ftell
U fwrite
U getenv
U gettimeofday
U glActiveTexture
U glBindTexture
U glBlendFunc
U glColor4f
U glDeleteTextures
U glDisable
U glDisableClientState
U glDrawArrays
U glDrawTexiOES
U glEnable
U glEnableClientState
U glGenTextures
U glGetError
U glGetIntegerv
U glGetString
U glLoadIdentity
U glMatrixMode
U glOrthof
U glPixelStorei
U glPopMatrix
U glPushMatrix
U glReadPixels
U glTexCoordPointer
U glTexEnvf
U glTexImage2D
U glTexParameteri
U glTexParameteriv
U glTexSubImage2D
U glVertexPointer
U glViewport
U __gnu_Unwind_Find_exidx
U log
U malloc
U memcmp
U nanosleep
U pow
U pthread_attr_destroy
U pthread_attr_init
U pthread_attr_setdetachstate
U pthread_cond_broadcast
U pthread_cond_destroy
U pthread_cond_init
U pthread_cond_signal
U pthread_cond_timedwait
U pthread_cond_wait
U pthread_create
U pthread_exit
U pthread_join
U pthread_kill
U pthread_mutexattr_init
U pthread_mutexattr_settype
U pthread_mutex_destroy
U pthread_mutex_init
U pthread_mutex_lock
U pthread_mutex_unlock
U pthread_self
U pthread_sigmask
U qsort
U raise
U realloc
U sem_destroy
U sem_getvalue
U sem_init
U sem_post
U sem_timedwait
U sem_trywait
U sem_wait
U __sF
U snprintf
U __stack_chk_fail
U __stack_chk_guard
U strcasecmp
U strchr
U strcmp
U strdup
U strlcpy
U strlen
U strncpy
U strstr
U tolower
U toupper
U truncf
$ nm -C -u project/obj/local/armeabi-v7a/libapplication.so
U __cxa_atexit
U __cxa_finalize
Also, i have these libs installed system-wide:
# sudo apt list --installed | grep sdl
libsdl-gfx1.2-5/xenial,now 2.0.25-5 amd64 [installed,automatic]
libsdl-gfx1.2-dev/xenial,now 2.0.25-5 amd64 [installed]
libsdl-image1.2/xenial-updates,xenial-security,now 1.2.12-5+deb9u1ubuntu0.16.04.1 amd64 [installed,automatic]
libsdl-image1.2-dev/xenial-updates,xenial-security,now 1.2.12-5+deb9u1ubuntu0.16.04.1 amd64 [installed]
libsdl-ttf2.0-0/xenial,now 2.0.11-3 amd64 [installed,automatic]
libsdl-ttf2.0-dev/xenial,now 2.0.11-3 amd64 [installed]
libsdl1.2-dev/xenial-updates,xenial-security,now 1.2.15+dfsg1-3ubuntu0.1 amd64 [installed]
libsdl1.2debian/xenial-updates,xenial-security,now 1.2.15+dfsg1-3ubuntu0.1 amd64 [installed,automatic]
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABF5QCF2A5OP352NHK7CPTSSPIORANCNFSM4UHNPF5A>
.
|
My project builds an executable, not a shared library. |
On Android every app is a shared librar wrapped in Java code. You build
executablea only when you build Android ROM.
…On Fri, 4 Dec 2020, 12:42 V, ***@***.***> wrote:
My project builds an executable, not a shared library.
I'm not using a custom build script or AndroidBuild.sh, i'll give that a
try.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABF5QEFHZ56ZPSIWA436JLSTC4IDANCNFSM4UHNPF5A>
.
|
I see a lot of Anyway i compiled the executable to x86 linux (using the usual procedure for it) and used AndroidBuild.sh to rename it to .so. The executable needs extra libs and i've seen in the readme i'll have to add them to program/jni and tinker with the Android.mk files, but can these libs be system libs (x86) or must they be arm(*)? I'm asking 'cos i've seen errors like "can't find file" or "unrecognized format" on libs that exist on my system, which leads me to think this is an architecture issue. Or does the NDK abstract away the architecture? |
Yes, you cannot use an executable in place of .so file and expect it to
work, and you cannot run x86 executable on ARM CPU.
The way an app works on Android is start Java virtual machine first (with
ART inside, but it's still Java) → run Java wrapper code → load your
libapplication.so
The 'executable' here is Java virtual machine, not your application main().
You can compile your own executable, but without Java support code, you can
only use command line, you cannot create video output or get touchscreen
input.
There is some support to build C++ apps without Java code inside Android
SDK, but my SDL port does not use it, because it was added long after I've
got my code to work.
…On Fri, 4 Dec 2020, 16:46 V, ***@***.***> wrote:
I see a lot of mv appbinary libapplication.so in many AndroidBuild.sh
files. I don't think an ELF binary is equivalent to a .so, is it? So i
assume there's a lot of magic surrounding the wrapping process. Or should
my appbinary be first compiled to arm instead of x86?
Anyway i compiled the executable to x86 linux (using the usual procedure
for it) and used AndroidBuild.sh to rename it to .so.
I set the CustomBuildScript=y and it compiled (a lot of SDL stuff) and
proceded to create an apk. Which crashes.
The executable needs extra libs and i've seen in the readme i'll have to
add them to program/jni and tinker with the Android.mk files, but can these
libs be system libs (x86) or must they be arm(*)? I'm asking 'cos i've seen
errors like "can't find file" or "unrecognized format" on libs that exist
on my system, which leads me to think this is an architecture issue.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABF5QDGIAPYB272XKQKQULSTDY3PANCNFSM4UHNPF5A>
.
|
Yes, it's a PEBKAC. I was confusing the concept of "native". My app compiles for x86 linux and windows. There are a lot of I think the A previous apk does have all libs and libapplication.so as arm, so... back to digital archaeology. :) |
The way i ended up fixing my issues was by making sure my app compiles with clang (had to fix some bugs 'cos clang seems to be pickier than gcc), change some flags and have the app be built by ./build.sh and custom build script.
Also some changes to the Makefile 'cos of clang:
|
I have an application that already uses SDL, and compiles for Windows and Linux.
I pulled the latest version of this project and, after reading the readme, was able to compile one of the demo applications. I had to fix licenses and gradle's java path.
However, i cannot compile my app, i always get his linker error:
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -Wl,-soname,libsdl_main.so -shared ./obj/local/armeabi-v7a/objs/sdl_main/sdl_main.o ./obj/local/armeabi-v7a/objs/sdl_main/SDL_android_main.o -lgcc -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -latomic -Wl,--exclude-libs,libatomic.a ./obj/local/armeabi-v7a/libsdl-1.2.so ./obj/local/armeabi-v7a/libapplication.so -target armv7-none-linux-androideabi16 -no-canonical-prefixes -Wl,--build-id -nostdlib++ -Wl,--no-undefined -Wl,--fatal-warnings -llog -lc -lm -o ./obj/local/armeabi-v7a/libsdl_main.so
jni/../jni/sdl_main/sdl_main.c:138: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/sdl_main.c:58: error: undefined reference to 'SDL_main'
jni/../jni/sdl_main/SDL_android_main.cpp:37: error: undefined reference to 'SDL_main'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/myuser/Android/Sdk/ndk/21.1.6352462/build/core/build-binary.mk:725: obj/local/armeabi-v7a/libsdl_main.so] Error 1
make: *** Waiting for unfinished jobs....
[armeabi-v7a] Install : libsdl-1.2.so => libs/armeabi-v7a/libsdl-1.2.so
install -p ./obj/local/armeabi-v7a/libsdl-1.2.so ./libs/armeabi-v7a/libsdl-1.2.so
/home/myuser/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded ./libs/armeabi-v7a/libsdl-1.2.so
I'm not sure if i'm missing some enviroment variables.
I've run
./changeAppSettings.sh
./project/jni/application/setEnvironment-x86_64.sh
but i have no LD_LIBRARY_PATH set, nor $CFLAGS or $LDFLAGS.
This is my system:
$ uname -a
Linux myhost-VirtualBox 4.15.0-123-generic #126~16.04.1-Ubuntu SMP Wed Oct 21 13:48:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"
$ javac -version
javac 1.8.0_275
(installed from openjdk-8-* packages)
$ /home/myuser/Android/Sdk/ndk/21.1.6352462/ndk-build -version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Help would be appreciated.
The text was updated successfully, but these errors were encountered: