OpenFL for Android with CrystaX NDK?

For now there is error when compiling with CrystaX NDK from here
Is it hard to fix?

Well, what kind of errors?

From what I learned from their project main page it’s a replacement for the google ndk, in that case you should try reporting your problems at hxcpp’s https://github.com/HaxeFoundation/hxcpp/issues/

Will be good to know what exactly fails. It could be either bug in OpenFL or bug in CrystaX NDK itself. If it’s bug of CrystaX NDK, we’d be happy to fix it, so please feel free to report us at https://tracker.crystax.net/projects/ndk.

Sorry for late details.
Lime SimpleImage sample linker errors:

arm-linux-androideabi-g++ -olibApplicationMain-v7.so -frtti -nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined -Wl,-z,noexecstack --sysroot=c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm -Lc:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib @obj/android-v7/all_objs c:\projects\devtools\crystax-ndk-10.1.0\/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o c:\projects\devtools\crystax-ndk-10.1.0\/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/libgcc.a c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib/libc.so c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib/libm.so -llog -ldl
c:/projects/devtools/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: obj/android-v7/0f13bae1_CFFI.obj: in function val_call0_traceexcept:CFFI.cpp(.text.val_call0_traceexcept+0xc0): error: undefined reference to '__stderrp'
c:/projects/devtools/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: obj/android-v7/0f13bae1_StdLibs.obj: in function __hxcpp_stdlibs_boot():StdLibs.cpp(.text._Z20__hxcpp_stdlibs_bootv+0x44): error: undefined reference to '__stdinp'
c:/projects/devtools/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: obj/android-v7/0f13bae1_StdLibs.obj: in function __hxcpp_stdlibs_boot():StdLibs.cpp(.text._Z20__hxcpp_stdlibs_bootv+0x48): error: undefined reference to '__stdoutp'
c:/projects/devtools/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: obj/android-v7/0f13bae1_StdLibs.obj: in function __hxcpp_stdlibs_boot():StdLibs.cpp(.text._Z20__hxcpp_stdlibs_bootv+0x4c): error: undefined reference to '__stderrp'
c:/projects/devtools/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: c:\projects\devtools\crystax-ndk-10.1.0\/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a(vterminate.o): in function __gnu_cxx::__verbose_terminate_handler():/home/cislave/workspace/ndk-build-linux-and-windows/toolchain/gcc/gcc-4.6/libstdc++-v3/libsupc++/vterminate.cc:82: error: undefined reference to '__stderrp'
collect2: ld returned 1 exit status
Error: error running arm-linux-androideabi-g++ -olibApplicationMain-v7.so -frtti -nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined -Wl,-z,noexecstack --sysroot=c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm -Lc:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib @obj/android-v7/all_objs c:\projects\devtools\crystax-ndk-10.1.0\/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o c:\projects\devtools\crystax-ndk-10.1.0\/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/libgcc.a c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib/libc.so c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm/usr/lib/libm.so -llog -ldl

And even compiler errors with Lime HandlingInputEvents sample:

arm-linux-androideabi-g++ -Iinclude --sysroot=c:\projects\devtools\crystax-ndk-10.1.0\/platforms/android-9/arch-arm -Ic:\projects\devtools\crystax-ndk-10.1.0\/sources/cxx-stl/gnu-libstdc++/4.6/include -Ic:\projects\devtools\crystax-ndk-10.1.0\/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=321 -IC:/projects/devtools/haxe_toolkit/haxe/lib/hxcpp/3,2,81/include -Iinclude -fpic -fvisibility=hidden -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums "-D_LINUX_STDDEF_H " -Wno-psabi -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -fomit-frame-pointer -fexceptions -fno-strict-aliasing -finline-limit=10000 -DANDROID=ANDROID -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=21 -Wa,--noexecstack -O2 -DNDEBUG -c -x c++ -Wno-invalid-offsetof -frtti ./src/lime/ui/Mouse.cpp -oobj/android-v7/a57b9b3a_Mouse.obj
Error: In file included from ./src/lime/ui/Mouse.cpp:4:0:
include/lime/_backend/native/NativeMouse.h:38:15: error: declaration does not declare anything [-fpermissive]

First off, I see gcc-4.6 used for build. It actually very outdated and CrystaX NDK provide more recent gcc versions (gcc-4.9 is default actually). I strongly recommend switch to gcc-4.9 since gcc-4.6 will be excluded from further releases.

Second, the problem goes from the fact that it don’t link with libcrystax.so, where symbols like __stderrp and others defined. As I see, custom build system used, and it don’t take into account CrystaX NDK peculiarities. For proper build with CrystaX NDK it should link binaries with libcrystax.so, putting it before libc.so and libm.so. This libcrystax.so then should be packaged into APK and distributed with other libraries. You can find one in $NDK/sources/crystax/libs/$ABI. All “undefined symbol” problems are going from the fact that libcrystax is not linked.

If I understand correctly it is possible to link crystax statically, isn’t it? to link to libcrystax.a?

Yes, it possible. However, be very careful - mixing static/shared libraries usually cause many troubles. libcrystax contains several static variables (since it override buggy Android libc) and it will lead to crashes and other wrong behaviour if final binary for some reason will contain several copies of such variables.

In other words, if you link with libcrystax statically, you should link statically all other libraries too. Otherwise, you should link dynamically all libraries, including libcrystax.

I’ve managed to build SimpleImage with CrystaX and it’s gcc-4.9, then tested it running on device.
Created an issue on hxcpp as a result :smile:
However I’m still getting this strange error:

include/lime/_backend/native/NativeMouse.h:38:15: error: declaration does not declare anything [-fpermissive]

Here what’s there on this line in NativeMouse.h:

static bool __hidden;

Now I don’t know what to do :confused:

Can you add any flags to make it handle this as a warning, not error?

__hidden is macro in CrystaX NDK, derived from BSD code. It’s defined as #define __hidden __attribute__((__visibility__("hidden"))), so obviously that line static bool __hidden becomes wrong.

In fact, this is wrong to use names starting from two underscores in any library code - according to C and C++ standards and best practices, such names are reserved to use by system implementations (such as CrystaX NDK).

So you should either #undef __hidden after all includes in NativeMouse.h or just rename that variable. Second approach is better actually, since it follow best practices.

Damn! Why haven’t I thought about that :slight_smile: I’ll try it and post about results.

I’d strongly recommend don’t do it! This is an error actually, and ignoring it with compiler flags will lead to all kinds of troubles. Better would be rename __hidden variable - it’s easy to do and will fix the error.

I understand what you mean, but my main purpose for now is just test lime app building with crystax and running on device :slight_smile:

Here it is.
Actually adding -fpermissive makes it even worse so that numerous errors appears here and there, something like this:

./src/lime/_backend/native/NativeMouse.cpp:359:40: error: expected unqualified-id before '__attribute__'

So I renamed this __hiden to _var_hidden and it worked!
It was just proof-of-concept tryout, nothing more :relaxed:

I don’t think any other compiler has had this problem. Do you think that perhaps (long-term) __hidden__ would be a better compiler macro? I’m used to seeing double underscores both before and after system code (such as __attribute__ and __visibility__)

This has nothing to compiler. This is part of system headers. CrystaX NDK uses a lot of BSD-derived code, and __hidden defined in BSD’s sys/cdefs.h file. Look here. So this code will have the same problems on any other system having BSD-derived system headers.

We could, of course, fix name of __hidden macro in CrystaX NDK; but this will fix just this one issue and not others. Better would be to follow C and C++ best practices and in library code don’t name any variables starting with one or two underscores.

It’s very common for people to use single underscores to denote private variables. In OpenFL and Lime, in order to prevent collision with user variables, the framework private variables use double underscores.

I guess I’ll have to decide whether to rename/avoid certain names on a case-by-case basis, or to use a different convention :confused: