Comments (11)
from commandergenius.
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'
from commandergenius.
from commandergenius.
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: thumb;@mthumb
Candidate multilib: armv7-a;@march=armv7-a
Candidate multilib: armv7-a/thumb;@march=armv7-a@mthumb
Candidate multilib: .;
Selected multilib: armv7-a;@march=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]
from commandergenius.
from commandergenius.
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.
from commandergenius.
from commandergenius.
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.
Or does the NDK abstract away the architecture?
from commandergenius.
from commandergenius.
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 #ifdef _ANDROID_
in the code, but i haven't gotten it to compile to arm yet.
I think the error: undefined reference to 'SDL_main'
is the linker trying to link different architectures (my app's x86 and the to-be-generated armeabi-v7a).
A previous apk does have all libs and libapplication.so as arm, so... back to digital archaeology. :)
from commandergenius.
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.
export ANDROID_NDK_HOME=${ANDROID_HOME}/ndk/21.1.6352462
export PATH=${ANDROID_NDK_HOME}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${JAVA_HOME}/bin:${PATH}
export PATH=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}
export CXX=clang++
export CXXFLAGS="-DNDEBUG -g2 -O3 -fstack-protector-all"
Also some changes to the Makefile 'cos of clang:
CXXFLAGS = std=gnu++11
CFLAGS = -stdlib=libc++ -D_GLIBCXX_USE_CXX11_ABI=0
from commandergenius.
Related Issues (20)
- fatal: Not a git repository (or any of the parent directories): .git
- running ./build.sh opentyrian results in an apk missing the assets files HOT 2
- debug always stripped, never signed HOT 6
- Help on how to emulate windows using android activities HOT 3
- Where do i look for command line arguments? HOT 6
- Intent Key HOT 1
- black screen after resume HOT 2
- OpenArena build.sh error ndk-build not found
- How to compile OA application.so.
- code/client/cl_main.c:27:10: fatal error: SDL_thread.h:No such file or directory
- How do you right click? (see strength of monsters) HOT 1
- Free heroes 2 android - cannot summon boat
- Ur quan for android hires doesn't work
- Unable to download Ur-Quan Masters Star Control 2 game content from Sourceforge server in app HOT 2
- Supertux for "Google TV" HOT 3
- [Mouse] OpenArena, XServer XSDL
- Build incomplete due to harfbuzz dependency on freetype HOT 4
- apk tries to unpack assets into wrong directory HOT 3
- Add support for usb gadget tool without kernel modifications HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commandergenius.