Hi im getting this error when i cross compile to android:
In file included from C:\Users\XXXX\develkinc\Shader-Kinc\Sources\@m..@sKinc@sSources@skinc@sgraphics4@sg4.nim.c:9:
C:\Users\XXXX\nim-1.4.2\lib\nimbase.h:542:1: error: static_assert failed due to requirement 'sizeof(int) == sizeof(void *) && 32 == sizeof(int) * 8' ""
comes from this line in nimbase.h:
// Test to see if Nim and the C compiler agree on the size of a pointer.
NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
using this build command:
nim c -c --cpu:arm --os:android -d:androidNDK --noMain:on --header:nimlib/nmain.h nimlib/nmain.nim
Android Studio will build your code for different CPU architectures (not just arm). So you need a way to tell it to pick the right arch.
Here is my Android.mk file showing how I did it:
LOCAL_PATH := $(call my-dir)
# To build these I downloaded the openssl source code, followed NOTES.ANDROID.
# Also used the commands here to get rid of versions in .so: https://github.com/openssl/openssl/issues/3902
# This tutorial was also somewhat useful: https://proandroiddev.com/tutorial-compile-openssl-to-1-1-1-for-android-application-87137968fee
#
# https://developer.android.com/ndk/guides/prebuilts#sa
include $(CLEAR_VARS)
LOCAL_MODULE := libssl
LOCAL_SRC_FILES := $(LOCAL_PATH)/dlls/$(TARGET_ARCH_ABI)/libssl.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := $(LOCAL_PATH)/dlls/$(TARGET_ARCH_ABI)/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := ../SDL
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include $(LOCAL_PATH)/../SDL2_image/
# https://developer.android.com/ndk/guides/android_mk#target_arch
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(TARGET_ARCH)/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_image libssl libcrypto
# See https://developer.android.com/ndk/guides/stable_apis for some of the APIs we can link against.
LOCAL_LDLIBS := -v -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
The important part is the line beginning with FILE_LIST.
Okay so Im trying to make nim generate the correct sizes again but for another project.
I'm trying to figure it out and I hit a wall.
This is the compiler build command in Android Studio (shortened for brevity):
C:/NVPACK/android-sdk-windows/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
--target=aarch64-none-linux-android21
--gcc-toolchain=C:/NVPACK/android-sdk-windows/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64
--sysroot=C:/NVPACK/android-sdk-windows/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot
Reading stuff from this older post i concluded that i must setup the cross compiler for Nim to generate the correct C code for this project: https://forum.nim-lang.org/t/1866
But I didn't know if this was the right thing to do nor how to do it.
nim.cfg:
# Examples of how to setup a cross-compiler:
arm64.linux.clang.path="C:/NVPACK/android-sdk-windows/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/bin/"
arm64.linux.clang.exe=
Is this the correct thing to do? Sorry this is the first time I do this ^_^