www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DMD2 - compiling and linking in separate steps (64-bit)

reply Sean Eskapp <eatingstaples gmail.com> writes:
I'm trying to use DMD through an IDE, but I'm getting stumped trying to
create 64-bit executables under Linux. I can get everything compiled fine,
using the -m64 compiler flag, but I can't get it to link. Here's the error
list:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libphobos2.a when searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libphobos2.a when
searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libphobos2.a when searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libm.so when searching
for -lm
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libm.a when searching for
-lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libpthread.so when
searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libpthread.a when
searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/librt.so when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/librt.a when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.so when searching
for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when searching
for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../librt.so when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../librt.a when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libc.a when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libc.so when searching
for -lc
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libc.a when searching for
-lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libc.a when searching for -lc
collect2: ld returned 1 exit status

How do I use ld to link 64-bit D executables?
Mar 18 2011
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday 18 March 2011 20:49:58 Sean Eskapp wrote:
 incompatible /usr/lib/../lib/librt.so when searching
 for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when searching
 for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../librt.so when searching for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../librt.a when searching for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../../lib/libc.so

Look at dmd.conf. It includes several flags which are supposed to be passed to the linker - either that or you can use dmd to link rather than using gcc on its own. Personally, I wouldn't bother compiling and linking as separate steps, but if you do, you need to make sure that you either use the flags in dmd.conf or you link with dmd rather than gcc. For the most part, there's no reason to link with gcc, even if you want to link separately. - Jonathan M Davis
Mar 18 2011
parent Sean Eskapp <eatingstaples gmail.com> writes:
== Quote from Jonathan M Davis (jmdavisProg gmx.com)'s article
 On Friday 18 March 2011 20:49:58 Sean Eskapp wrote:
 incompatible /usr/lib/../lib/librt.so when searching
 for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when searching
 for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../librt.so when searching for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../librt.a when searching for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../../lib/libc.so

the linker - either that or you can use dmd to link rather than using gcc on its own. Personally, I wouldn't bother compiling and linking as separate steps, but if you do, you need to make sure that you either use the flags in dmd.conf or you link with dmd rather than gcc. For the most part, there's no reason to link with gcc, even if you want to link separately. - Jonathan M Davis

Hmm.. after linking with all the options in dmd.conf (-L/usr/lib32 -L/usr/lib64 --no-warn-search-mismatch --export-dynamic -lrt), I still get /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-system.a when searching for -ldsfml-system /usr/bin/ld: cannot find -ldsfml-system /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-graphics.a when searching for -ldsfml-graphics /usr/bin/ld: cannot find -ldsfml-graphics /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-audio.a when searching for -ldsfml-audio /usr/bin/ld: cannot find -ldsfml-audio /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-window.a when searching for -ldsfml-window /usr/bin/ld: cannot find -ldsfml-window collect2: ld returned 1 exit status Now, I compiled libdsfml-system.a myself, and I know they're 64-bit, so this implies ld still isn't recognizing that I want 64-bit executables.
Mar 19 2011
prev sibling parent "Jason E. Aten" <j.e.aten gmail.com> writes:
On Sat, 19 Mar 2011 13:52:05 +0000, Sean Eskapp wrote:

 == Quote from Jonathan M Davis (jmdavisProg gmx.com)'s article
 On Friday 18 March 2011 20:49:58 Sean Eskapp wrote:
 incompatible /usr/lib/../lib/librt.so when searching for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when
 searching for -lrt
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../librt.so when searching for -lrt /usr/bin/ld:
 skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../librt.a when searching for -lrt /usr/bin/ld:
 skipping incompatible /usr/lib/gcc/x86_64-linux-
 gnu/4.4.5/../../../../lib/libc.so

passed to the linker - either that or you can use dmd to link rather than using gcc on its own. Personally, I wouldn't bother compiling and linking as separate steps, but if you do, you need to make sure that you either use the flags in dmd.conf or you link with dmd rather than gcc. For the most part, there's no reason to link with gcc, even if you want to link separately. - Jonathan M Davis

Hmm.. after linking with all the options in dmd.conf (-L/usr/lib32 -L/usr/lib64 --no-warn-search-mismatch --export-dynamic -lrt), I still get /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-system.a when searching for -ldsfml-system /usr/bin/ld: cannot find -ldsfml-system /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-graphics.a when searching for -ldsfml-graphics /usr/bin/ld: cannot find -ldsfml-graphics /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-audio.a when searching for -ldsfml-audio /usr/bin/ld: cannot find -ldsfml-audio /usr/bin/ld: skipping incompatible /home/me/devl/sfml2/bindings/d/lib/libdsfml-window.a when searching for -ldsfml-window /usr/bin/ld: cannot find -ldsfml-window collect2: ld returned 1 exit status Now, I compiled libdsfml-system.a myself, and I know they're 64-bit, so this implies ld still isn't recognizing that I want 64-bit executables.

I think the reason that ld is skipping those libraries is that secretly, inside the .a archives, they are really 32-bit libraries and not 64-bit libraries. You can confirm this by using the "ar x {somelibrary}.z" to extract the object files (do it from a new temp directory), and then running "file {new}.o", which in my hands reports that the dmd libraries such as phobos are actually 32-bit, even on x86_64 linux. This is why I went to LDC2, which is fully 64-bit. - Jason
Mar 21 2011