gcc linkage problem with C & D

Charles D Hixson charleshixsn at earthlink.net
Thu Jul 26 15:11:43 PDT 2007


Frits van Bommel wrote:
> Charles D Hixson wrote:
>> a bust.  But this means that I'm going to need to pass into the linker 
>> the output of `pkg-config --libs gtk+-2.0`, which doesn't appear to 
>> pass correctly to dmd. (I can't even see any compiler options for 
>> accepting it...you'd think that -L might work, but if it will I 
>> haven't out how to cause it to.)
> 
> Two options:
> 
> 1) Pass "-L$(DMD_DIR)/lib -lphobos -lpthread -lm" to gcc or ld when 
> using either for linking (these are the libs D requires when compiled 
> with dmd, IIRC).
> 
> 2) Pass something like $(addprefix -L, $(shell pkg-config --libs 
> gtk+-2.0)) to dmd when using it for linking. This will add '-L' in front 
> of every library specification; the reason just adding -L didn't work 
> was that your command adds multiple libraries.

The short of it is:
md  -c test0d.d
gcc -g -I/usr/include/gdk  -c test0c.c -o test0c.o
gcc -g -I/usr/include/gdk       -WAll  -L/usr/local/dmd/lib 
-lphobos -lpthread -lm test0d.o test0c.o -o test0
/usr/local/dmd/lib/libphobos.a(dmain2.o): In function `main':
internal/dmain2.d:(.gnu.linkonce.tmain+0x74): undefined 
reference to `_Dmain'
internal/dmain2.d:(.gnu.linkonce.tmain+0xc5): undefined 
reference to `_Dmain'
/usr/local/dmd/lib/libphobos.a(deh2.o): In function 
`_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable':
internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9): 
undefined reference to `_deh_beg'
internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe): 
undefined reference to `_deh_beg'
internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14): 
undefined reference to `_deh_end'
internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): 
undefined reference to `_deh_end'
collect2: ld returned 1 exit status
make: *** [test0] Error 1


Which totally boggles me.  This is what I rewrote the Makefile to:
CC = gcc -g -I/usr/include/gdk
CD = dmd
DMD_DIR = /usr/local/dmd
DLNK = -L$(DMD_DIR)/lib -lphobos -lpthread -lm

all:  test0

test0:  test0d.o test0c.o
	$(CC)	-WAll  $(DLNK) test0d.o test0c.o -o test0

test0d.o:
	$(CD)  -c test0d.d

test0c.o: test0c.c
	$(CC)  -c test0c.c -o test0c.o

clean:
	rm -f *.o  test0


(minus some wrapping that happened in posting).  The other 
files are unchanged:  test0c.c is a "hello, world" function, 
and test0d.d is a main routine that just calls the function.

$ ls /usr/local/dmd
bin  html  lib  license.txt  man  readme  samples  src

and
$ ls /usr/local/dmd/lib
gcstub.obj  libphobos.a  phobos.lib  readme.txt  WS2_32.LIB
(basically I just copied the dmd folder to /usr/local after 
unzipping it)

$ cat /etc/dmd.conf

[Environment]

DFLAGS=-I/usr/local/dmd/src/phobos -L-L/usr/local/dmd/lib

(I know I'm sort of flailing around here, but I haven't a clue 
as to what the problem is.)


More information about the Digitalmars-d-learn mailing list