DMD will happily combine static library files for different architectures. This confuses the linker.
Steps to reproduce (performed on 64-bit Linux):
1. Write libfoo.d.
void foo() { }
2. Write libbar.d.
void bar() { }
3. Compile libfoo as 32-bit library.
dmd -lib -m32 libfoo.d
4. Compile libbar as 64-bit library, including libfoo.
dmd -lib -m64 -oflibbar.a libfoo.a libbar.d
5. Compile any program with -m64 -lbar
/usr/bin/ld: skipping incompatible ./libbar.a when searching for -lbar
/usr/bin/ld: cannot find -lbar
ld accepts the library if -m32 is specified in step 5, but complains about the 64-bit object files.
This is the model upon which druntime+Phobos is compiled. I spent an hour trying to figure out why the linker didn't recognise the 64-bit libphobos2.a, until I realised that it had been compiled with a 32-bit version of libdruntime.a. :(
Comment #1 by post — 2011-06-10T07:01:19Z
Simple solution: Detect architecture of the first object file in the archive and take that to be the architecture of the library.
Comment #2 by andrei — 2016-10-14T16:53:20Z
Fixing this would be quite nice.
Comment #3 by robert.schadek — 2024-12-13T17:55:29Z