nim-lang / csources_v1

CSources compiled from Nim version 1. Supports more CPU/OS combinations than the older csources repository.
MIT License
15 stars 9 forks source link

Build fails on Mac M1 with linker error #8

Open cskiraly opened 1 year ago

cskiraly commented 1 year ago

Build fails on Mac M1 with message "building for macOS-arm64 but attempting to link with file built for unknown-x86_64"

% clang --version
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Also note that the error message is hidden during nim build in the nimbus-build system, if not using make V=1.

Underlying issue

clang is compiling binaries to x86_64. Running the same command from command-line compiles to arm64.

Workaround found

To debug what happens I've added -v to CFLAGS, and the compilation magically changes to arm64. Really strange -v being verbose output. I suspect an underlying clang bug.

Anyway the workaround is below. Note that make clean is required.

diff --git a/makefile b/makefile
index 503c030..9326ac3 100644
--- a/makefile
+++ b/makefile
@@ -3,7 +3,7 @@
 # To regenerate run ``niminst csource`` or ``koch csource``

 CC ?= gcc
-CFLAGS += -Ic_code -w -O3 -fno-strict-aliasing
+CFLAGS += -Ic_code -w -O3 -fno-strict-aliasing -v
 LDFLAGS +=
 binDir = bin
Araq commented 1 year ago

I did run that myself on the M1 without any issue. I've been using Nim on the M1 now for months successfully.

cskiraly commented 1 year ago

I also had it running for long on M1 compiling Nim many times, then I've bumped into this just now. As I've said, I think it is clang version specific, so I wouldn't modify the code, just keep this issue around for people who bump into the same problem.