I am on a m2 mac and any nim program I try to compile with the --cpu:arm option It gives me the error
_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "Pointer size mismatch between Nim and C/C++ backend. You probably need to setup the backend compiler for target CPU.");
I'm not really an experienced programmer I'm just learning for fun so I'm not quite sure how to fix this. I sort of need to compile for arm since there's a dylib I need but it's in the arm64 architecture and it never gets found I think because for some reason it compiles to x86_64 by default.
Did you install Nim using choosenim? On arm macs it still installs macos x64_64 which runs via rosetta.
The easiest solution I found is to install Nim using asdf: https://asdf-vm.com/guide/getting-started.html
Bonus is that the compiler runs quicker.
A few things I can think of to verify. Check the nim binary:
file `which nim`
and will output something similar to:
/opt/homebrew/bin/nim: Mach-O 64-bit executable arm64
then test the binary that was created by nim:
file ./main
A few other things I found that shows how the compiler finds the runtime cpu values:
macosx: i386;amd64;powerpc64;arm64
and the definitions are found in platform.nim.
BTW I was able to reproduce the error you initially mentioned here. Looking at installer.ini maybe it is only for linux?
In that case make sure you also use —cpu:arm64 as well. The static assert occurs when you’re telling Nim to compile for arm (32 bit) but the C compiler is using arm64 (64 but).
Generally it’s best to not provide the —cpu option and just make sure you install the arm64 version from brew or elsewhere. Then Nim will use the local arch, arm64. Sometimes I’ve had to uninstall Nim (choosenim) and install via brew to get rid of x86_64 settings.