www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - 64-bit two-step compilation on Ubuntu?

reply Sean Eskapp <email email.com> writes:
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?
Apr 25 2011
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
 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
Apr 25 2011
parent reply Sean Eskapp <noemail gmail.com> writes:
== Quote from Jonathan M Davis (jmdavisProg gmx.com)'s article
 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?

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

How do I use dmd as the linker separately from using it as the compiler? As you can see in my original post, I'm passing -m64 to DMD, but it doesn't seem to be picking it up..
Apr 25 2011
parent Sean Eskapp <noemail gmail.com> writes:
== Quote from Jonathan M Davis (jmdavisProg gmx.com)'s article
 == Quote from Jonathan M Davis (jmdavisProg gmx.com)'s article

 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

How do I use dmd as the linker separately from using it as the compiler? As you can see in my original post, I'm passing -m64 to DMD, but it doesn't seem to be picking it up..

Otherwise, it'll link the .o files and produce a binary. If you're doing 2 step compilation, then you must be passing -c to dmd for the first step. So, for the second step, just give it the .o files instead of the .d files and don't pass it -c. As for -m64, if you have a version of dmd prior to 2.052, then it only does 32-bit compilation. If you have 2.052, then it should accept -m64 and produce 64-bit .o files, and produce a 64-bit binary when when not using -c. If that doesn't work, then it needs to be reported in bugzilla. - Jonathan M Davis

I reinstalled dmd, changed up my compiler flags from global and project-specific to just project specific in Code::Blocks, and removed the unnecessary - melf_x86_64 linker flag, and it seems to have started working. Thanks!
Apr 25 2011
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
 == Quote from Jonathan M Davis (jmdavisProg gmx.com)'s article
 
 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

How do I use dmd as the linker separately from using it as the compiler? As you can see in my original post, I'm passing -m64 to DMD, but it doesn't seem to be picking it up..

If you pass -c to dmd, it won't link, but will just produce .o files. Otherwise, it'll link the .o files and produce a binary. If you're doing 2 step compilation, then you must be passing -c to dmd for the first step. So, for the second step, just give it the .o files instead of the .d files and don't pass it -c. As for -m64, if you have a version of dmd prior to 2.052, then it only does 32-bit compilation. If you have 2.052, then it should accept -m64 and produce 64-bit .o files, and produce a 64-bit binary when when not using -c. If that doesn't work, then it needs to be reported in bugzilla. - Jonathan M Davis
Apr 25 2011