Discussion:
Linker not working under dmd
Jonathan Marler
2014-04-04 22:08:30 UTC
Permalink
I'm having a problem with the DMD compiler but it seems I can't
post to the digitalmars.D.bugs thread for help, so I'm posting
here.

I'm getting the "/usr/bin/ld: cannot find -l:libphobos2.a" error
when I run dmd. I've looked at all the threads and tried
everything but nothing seems to have worked.

I downloaded dmd.2.065.0.zip to a redhat 64bit machine and
followed the installation instructions from
http://dlang.org/dmd-linux.html:
Unzip the archive into your home directory. It will create a
~/dmd directory with all the files in it. All the tools are
command line tools, which means they are run from a console
window.
Copy dmd.conf to /etc:
cp dmd2/linux/bin/dmd.conf /etc
Put dmd2/linux/bin on your PATH, or copy the linux
executables to /usr/local/bin
Copy the library to /usr/lib:
cp dmd2/linux/lib/libphobos2.a /usr/lib

I tried this with both the lib32 binaries and the lib64 binaries.
After I copied the dmd.conf to the /etc path I added the
absolute paths to the arguments like so:
[Environment32]
DFLAGS=-I/root/dmd2/src/phobos
-I/root/dmd2/src/druntime/import -L-L/root/dmd2/linux/lib32
-L--export-dynamic

[Environment64]
DFLAGS=-I/root/dmd2/src/phobos
-I/root/dmd2/src/druntime/import -L-L/root/dmd2/linux/lib64
-L--export-dynamic

I know the dmd.conf file is working because when I change this
file I see the results when I run dmd. However no matter what I
do I never get past the same error message:

/usr/bin/ld: cannot find -l:libphobos2.a
collect2: ld returned 1 exit status
--- errorlevel 1


I've tried:

1. Setting LD_LIBRARY_PATH
2. Copying the libphobos2.a file to /lib, /usr/lib,
/usr/local/lib (the last one is the default in /etc/ld.so.conf)
3. Changing dmd.conf -L-L argument any which way I can (added a
colon, a space, tried other option letters)

After nothing worked I tried just changing my path instead.

export PATH=/root/dmd2/linux/bin64:$PATH

It then used the dmd.conf file in the unzipped directory (instead
of the one in /etc/dmd.conf) but it still didn't find
libphobos2.a.

I feel like I've tried everything, I'm at my wits end with this.

I'm running as root, the lib files are veiwable by everyone so
that's not the problem.

I tried running ld on the .o file created by dmd, but I'm not
sure what arguments dmd uses, if someone knows could you provide
me with the arguments and I can try running ld along (without
dmd).
Adam D. Ruppe
2014-04-05 00:28:54 UTC
Permalink
I had this problem too with the new dmd version on a CentOS
server.

My solution was to link it manually. First, run your dmd command
with -v at the end to get the verbose output. The last line it
outputs will be the linking command.

Copy/paste that and find where it does the -l:phobos2 or whatever
it exactly looks like. Delete it and instead use plain -lphobos2,
no weirdo colon.

Then it should work. I changed my makefile to always compile and
link separately on that box so I wouldn't have to worry about it
later.

(i also had to recompile phobos on that box because the libc was
too old for the qsort_r druntime now uses. If you have that
problem too, let me know and I'll tell you what I did.)
Adam D. Ruppe
2014-04-05 00:29:55 UTC
Permalink
The link command on mine btw is:

gcc *.o -o content -m32 -L/home/user/dmd2/linux/bin32/../lib32
-Xlinker -- export-dynamic -lpq -lmhash -lcurl -lphobos2
-lpthread -lm -lrt


The pq, mhash, and curl libraries are used by my application so
you might not need those on your app. This is also a 32 bit
program.
Mike Wey
2014-04-05 10:57:50 UTC
Permalink
I had this problem too with the new dmd version on a CentOS server.
My solution was to link it manually. First, run your dmd command with -v
at the end to get the verbose output. The last line it outputs will be
the linking command.
Copy/paste that and find where it does the -l:phobos2 or whatever it
exactly looks like. Delete it and instead use plain -lphobos2, no weirdo
colon.
Then it should work. I changed my makefile to always compile and link
separately on that box so I wouldn't have to worry about it later.
Or add "-defaultlib=phobos2" to dmd.conf
(i also had to recompile phobos on that box because the libc was too old
for the qsort_r druntime now uses. If you have that problem too, let me
know and I'll tell you what I did.)
--
Mike Wey
Jonathan Marler
2014-04-07 16:26:33 UTC
Permalink
Post by Adam D. Ruppe
I had this problem too with the new dmd version on a CentOS
server.
My solution was to link it manually. First, run your dmd
command with -v at the end to get the verbose output. The last
line it outputs will be the linking command.
Copy/paste that and find where it does the -l:phobos2 or
whatever it exactly looks like. Delete it and instead use plain
-lphobos2, no weirdo colon.
Then it should work. I changed my makefile to always compile
and link separately on that box so I wouldn't have to worry
about it later.
(i also had to recompile phobos on that box because the libc
was too old for the qsort_r druntime now uses. If you have that
problem too, let me know and I'll tell you what I did.)
Thanks so much for the help, it's good to know I'm not alone in
the D world. It's hard being the first one at my job to start
using D but this language has almost all the things that I've
been wanting from C/C++.
Rafael via Digitalmars-d
2014-10-10 15:02:16 UTC
Permalink
Post by Adam D. Ruppe
I had this problem too with the new dmd version on a CentOS
server.
My solution was to link it manually. First, run your dmd
command with -v at the end to get the verbose output. The last
line it outputs will be the linking command.
Copy/paste that and find where it does the -l:phobos2 or
whatever it exactly looks like. Delete it and instead use plain
-lphobos2, no weirdo colon.
Then it should work. I changed my makefile to always compile
and link separately on that box so I wouldn't have to worry
about it later.
(i also had to recompile phobos on that box because the libc
was too old for the qsort_r druntime now uses. If you have that
problem too, let me know and I'll tell you what I did.)
Hi, Adam,
I have old gstdlibc too (without qsort_r). Please, tell
workaround to recompile phobos.

Thanks in advance!
Walter Bright
2014-04-05 01:10:57 UTC
Permalink
I tried running ld on the .o file created by dmd, but I'm not sure what
arguments dmd uses, if someone knows could you provide me with the arguments and
I can try running ld along (without dmd).
If you run dmd with the -v switch, it will show the command it passes to the linker.
Nick Sabalausky via Digitalmars-d
2014-10-10 20:56:38 UTC
Permalink
I'm having a problem with the DMD compiler but it seems I can't post to
the digitalmars.D.bugs thread for help, so I'm posting here.
digitalmars.D.bugs isn't intended for posting or for getting help, it's
just a place that automatically mirrors issues/comments that get posted
to the bugzilla issue tracker: https://issues.dlang.org/

Even though its name may suggest a more limited scope,
digitalmars.D.learn is really for pretty much any general D-related help.
Loading...