I saw this page and tested the packages that are mentioned there (Game Development and GUI). Unfortunately none of them work on android (I just tested on arm64 Nougat API 24):-(
For SDL2 there are many implementations one of them official.
Some packages end with the following error: error: 'Nim_and_C_compiler_disagree_on_target_architecture'
Compile error from nimx package example:
../../.nimble/pkgs/nimfp-0.4.3/fp/option.nim(42, 36) Error: 'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period; usage of '==' is a user-defined error
In file included from /home/hdias/.cache/nim/test_d/test.c:10:
/home/hdias/Downloads/tmp/Nim-0.19.4/lib/nimbase.h:490:64: error: 'Nim_and_C_compiler_disagree_on_target_architecture' declared as an array with a negative size
typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from /home/hdias/.cache/nim/test_d/stdlib_system.c:10:
/home/hdias/tmp/Nim-0.19.4/lib/nimbase.h:490:64: error: 'Nim_and_C_compiler_disagree_on_target_architecture' declared as an array with a negative size
typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any idea?
Looks like you haven't set the cross compiler to the correct architecture. The error is the architecture Nim targets is different from what the underlying C compiler targets.
Passing the correct compiler via the switch --gcc.exe:/path/to/C/cross/compiler and --gcc.linkerexe:/path/to/C/cross/compiler should fix the problem.
I think the problem is not the cross compiler, I can compile and run a "Hello Wold" simple test. I use the NDK as shown below:
/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \
-I/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
-I/home/hdias/tmp/Nim-0.19.4/lib \
-fPIE -pie -o /home/hdias/tmp/testgui.bin \
/home/hdias/.cache/nim/test_d/testgui.c \ /home/hdias/.cache/nim/testgui_d/stdlib_system.c
I tried to compile some Examples from SDL Nim official package for android, but without success!
Anyone have any ideas how to do it?
$ /home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \
-I/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -I/home/hdias/tmp/SDL2-2.0.9 \
-I/home/hdias/tmp/Nim-0.19.4/lib \
-I/home/hdias/tmp/SDL2-2.0.9/include \
-fPIE -pie -o /home/hdias/tmp/test.bin \
/home/hdias/.cache/nim/test_d/test.c /home/hdias/.cache/nim/test_d/stdlib_system.c
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_macrosDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_parseutilsDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_bitopsDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_mathDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_algorithmDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_unicodeDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_strutilsDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'sdl2_sdl2DatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'sdl2_gfxDatInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_macrosInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_parseutilsInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_bitopsInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_mathInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_algorithmInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_unicodeInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'stdlib_strutilsInit000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'sdl2_sdl2Init000'
/tmp/test-1e7f7e.o:test.c:function PreMainInner: error: undefined reference to 'sdl2_gfxInit000'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'toBool_3fq5Y9cfgYx8q7J9ba6TTYbQ'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_255222_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'defaultEvent_LbtYyFPe9bpTC9bKZ8rWJeKQ'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_251437_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_252008_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_251391_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_251274_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_252318_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_255239_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_251675_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_251656_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_251230_'
/tmp/test-1e7f7e.o:test.c:function NimMainModule: error: undefined reference to 'Dl_255231_'
/tmp/test-1e7f7e.o:test.c:function destroy_sFvfWODyHxg46OuBtGyU8Qtest: error: undefined reference to 'Dl_252040_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Yes is possible create a app in Nim for android and iOS the solution is here and works :-) After install the wiish package, sdk and ndk for android setup an app is easy:
$ wiish init testapp
$ nano -w testapp/dist/android/project/org.wiish.webviewexample/local.properties
sdk.dir=/usr/local/android/sdk
ndk.dir=/usr/local/android/ndk
$ wiish build --android testapp
$ wiish run --android testapp
$ cd androidtestapp/dist/android/project/org.wiish.webviewexample/app/build/outputs/apk/debug/
$ adb install app-debug.apk
Can you try invoking the compiler like this instead?
nim --cc:clang --clang.exe:/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang --clang.linkerexe:/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang --os:android --cpu:arm64 -t:-I/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot test.nim
This should let Nim know which cross compiler should be used.
I've tried your solution, but it does not work. When I execute the command it gives the following result:
$ nim --cc:clang --clang.exe:/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang --clang.linkerexe:/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang --os:android --cpu:arm64 -t:-I/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot test.nim
Hint: used config file '/home/hdias/.choosenim/toolchains/nim-0.19.4/config/nim.cfg' [Conf]
Error: invalid command: test.nim
But as I said before I can compile a simple "Hello World!" nim code. At this time the fastest way to make an app in Nim is to use the Wiish package.