cAPI FFI linking issue: Multiple definitions message does not guide towards resolution
While using CApi I encountered this bug (original report here)
Error message:
Building executable 'capi-linker-error' for capi-linker-error-0.1.0.0...
[2 of 2] Linking /tmp/capi-linker-error/dist-newstyle/build/x86_64-linux/ghc-9.9.20231111/capi-linker-error-0.1.0.0/x/capi-linker-error/build/capi-linker-error/capi-linker-error
/usr/bin/ld.gold: error: /tmp/capi-linker-error/dist-newstyle/build/x86_64-linux/ghc-9.9.20231111/capi-linker-error-0.1.0.0/x/capi-linker-error/build/capi-linker-error/capi-linker-error-tmp/app/foo.o: multiple definition of 'foo'
/usr/bin/ld.gold: /tmp/capi-linker-error/dist-newstyle/build/x86_64-linux/ghc-9.9.20231111/capi-linker-error-0.1.0.0/x/capi-linker-error/build/capi-linker-error/capi-linker-error-tmp/Main.o: previous definition here
collect2: error: ld returned 1 exit status
ghc-9.9.20231111: `gcc' failed in phase `Linker'. (Exit code: 1)
Error: [Cabal-7125]
Failed to build exe:capi-linker-error from capi-linker-error-0.1.0.0.
Minimal reproducer: https://github.com/brcha/capi-linker-error/
Using foo.h
instead of foo.c
is the fix, but the error message doesn't reflect this.
Edited by Hécate Kleidukos