64-bit two-step compilation on Ubuntu?

Jonathan M Davis jmdavisProg at gmx.com
Mon Apr 25 12:35:58 PDT 2011


> I'm trying to get a D2 project to build on Ubuntu through Code::Blocks.
> Unfortunately, Code::Blocks doesn't allow the simple one-step compilation
> that is default with dmd, so it does compiling and linking in two separate
> steps. Unfortunately, this is causing some linker errors, the main one
> being:
> 
> /usr/bin/ld: i386 architecture of input file `obj/Debug/main.o' is
> incompatible with i386:x86-64 output
> 
> I've tried passing -melf_x86_64 to the linker, and that doesn't change
> anything. I'm also trying to pass -m64 to the compilation step, and it
> doesn't work. Help?

First thing I'd try would be to use dmd as the linker.

dmd compiles in 32-bit by default. Assuming that you're using dmd 2.052, then 
you can use -m64 to tell it to compile for 64-bit, at which point linking with 
gcc should work. Otherwise, you'd need to pass -m32 to gcc when linking 
(unless you're using ld directly (at which point, I don't know what you do), 
and I'm not aware of anyone doing that - dmd doesn't). Regardless, if you're 
linking separately and not using dmd for the linking step, then you need to 
look at dmd.conf and make sure that you include the linker flags that it does, 
or your code may not work.

In any case, my best suggestion if you can't compile and link in one step 
would be to just use dmd for both.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list