www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linker not working under dmd

reply "Jonathan Marler" <johnnymarler gmail.com> writes:
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).
Apr 04 2014
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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.)
Apr 04 2014
parent Mike Wey <mike-wey example.com> writes:
On 04/05/2014 02:28 AM, Adam D. Ruppe wrote:
 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
Apr 05 2014
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Apr 04 2014
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 4/4/2014 3:08 PM, Jonathan Marler wrote:
 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.
Apr 04 2014
prev sibling parent "Jonathan Marler" <johnnymarler gmail.com> writes:
On Saturday, 5 April 2014 at 00:28:55 UTC, Adam D. Ruppe wrote:
 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++.
Apr 07 2014