gcc linkage problem with C & D
Charles D Hixson
charleshixsn at earthlink.net
Thu Jul 26 15:28:13 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.
OK, this time following the other path, here's the short:
$ make -fMakefile2.test0
gcc -g -I/usr/include/gdk -c test0c.c -o test0c.o
dmd test0d.d test0c.o -L-lgtk-x11-2.0 -L-lgdk-x11-2.0
-L-latk-1.0 -L-lgdk_pixbuf-2.0 -L-lm -L-lpangocairo-1.0
-L-lfontconfig -L-lXext -L-lXrender -L-lXinerama -L-lXi
-L-lXrandr -L-lXcursor -L-lXfixes -L-lpango-1.0 -L-lcairo
-L-lX11 -L-lgobject-2.0 -L-lgmodule-2.0 -L-ldl -L-lglib-2.0
gcc test0d.o test0c.o -o test0d -m32 -lgtk-x11-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0
-lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr
-lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0
-lgmodule-2.0 -ldl -lglib-2.0 -Xlinker -L/usr/local/dmd/lib
-lphobos -lpthread -lm
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../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
--- errorlevel 1
make: *** [test0] Error 1
and here's the makefile:
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: test0c.o
$(CD) test0d.d test0c.o $(addprefix -L, $(shell pkg-config
--libs gtk+-2.0))
test0c.o: test0c.c
$(CC) -c test0c.c -o test0c.o
clean:
rm -f *.o test0
as before, the post wrapped the makefile, but that's pretty
clear. The system config is unchanged. And I'm confused.
Well, this test case shouldn't need those extra libraries in
gtk, so I tried eliminating them in Makefile3.test0:
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: test0c.o
$(CD) test0d.d test0c.o
test0c.o: test0c.c
$(CC) -c test0c.c -o test0c.o
clean:
rm -f *.o test0
but running it yielded no improvement:
$ make -fMakefile3.test0
gcc -g -I/usr/include/gdk -c test0c.c -o test0c.o
dmd test0d.d test0c.o
gcc test0d.o test0c.o -o test0d -m32 -Xlinker
-L/usr/local/dmd/lib -lphobos -lpthread -lm
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../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
--- errorlevel 1
make: *** [test0] Error 1
More information about the Digitalmars-d-learn
mailing list