gcc linkage problem with C & D

Carlos Santander csantander619 at gmail.com
Wed Jul 25 18:15:30 PDT 2007


Charles D Hixson escribió:
> Here's what I have.  I hope it makes sense to other people:
> test0c.c is -->
> #include    <stdio.h>
> 
> int    test()
> {  printf ("Hello, world\n");
>    return  0;
> }
> 
> //int main(int argc, char *argv[])
> //{    return    test(argc, argv);    }
> 
> test0d.d is -->
> extern(C):
>     int    test();
> 
> void    main()
> {    test;    }
> 
> Makefile.test0 is -->
> all:  test0
> 
> test0:  test0d.o test0c.o
>     $(CC)    test0d.o test0c.o -o test0
> 
> test0d.o:
>     dmd  -c test0d.d $(LL)  -I~/src/phobos test0c.o
> 
> test0c.o: test0c.c
>     $(CC)  -c test0c.c -o test0c.o
> 
> clean:
>     rm -f *.o  test0
> 
> THEN:
> $ make -fMakefile.test0
> dmd  -c test0d.d   -I~/src/phobos test0c.o
> cc  -c test0c.c -o test0c.o
> cc      test0d.o test0c.o -o test1
> test0d.o: In function `gcc2_compiled.':
> test0d.d:(.text+0x8): undefined reference to `_Dmodule_ref'
> collect2: ld returned 1 exit status
> make: *** [test0] Error 1
> 
> I don't know how to even get started addressing this problem.  bud dies 
> with even less informative messages.

You're missing -lphobos (-lgphobos if you were using GDC). The easiest way to do 
it is like this:

dmd -c test0d.d
cc -c test0c.c -o test0c.o
dmd test0d.o test0c.o

That first step is only if you absolutely require separate commands for 
compiling and linking. Otherwise, you could remove it and pass test0d.d to DMD 
instead of test0d.o.

Also, if DMD is properly set up, you shouldn't need to pass -I~/src/phobos to it.

-- 
Carlos Santander Bernal


More information about the Digitalmars-d-learn mailing list