gcc linkage problem with C & D

Charles D Hixson charleshixsn at earthlink.net
Wed Jul 25 18:55:22 PDT 2007


Carlos Santander wrote:
> 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.
Well, if I can figure out how to do this I'm going to be 
passing calls to things written by GLADE, and only lightly 
edited.  This is just a test run to try to figure out how to 
make the linkage work.  So far it's 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.)


> Also, if DMD is properly set up, you shouldn't need to pass 
> -I~/src/phobos to it.
Fixed this one.  The @P variable in dmd.conf doesn't work 
correctly if you're using links to the binary routines.


More information about the Digitalmars-d-learn mailing list