D not able to link .o files

Bill Baxter dnewsgroup at billbaxter.com
Mon Feb 25 11:20:28 PST 2008


Tim Healey wrote:
> meldolion wrote:
>> I tried to include a external c function created by MinGW in a D source.
>>
>> so I got a helloworld.o file
>>
>> when i want to compile my main.d module with following command:
>>
>> dmd main.d helloworld.o I get the error
>> Error: unrecognized file extension o
>>
>> How can I solve that problem
>>
>> thx for help
>> meldolion
> 
> Different compilers use different object formats. It would probably be
> easier to either compile the C program with Digital Mars C and continue
> using DMD or compile the D program with GDC and continue using MinGW.

BTW, if you got your DMD installation from DigitalMars.com (and not from 
the Tango folks) then you already have a copy of "dmc" the DigitalMars 
C++ compiler.

Additionally, one way to get around the object file differences is to 
build a DLL, since the DLL format is standardized.

Given a MinGW library called libThing.a you can build a shared lib with 
a crazy command line like this:

gcc -mno-cygwin -shared -o Thing.dll \
    -Wl,--out-implib=Thing_mingw.lib \
    -Wl,--export-all-symbols -Wl,--allow-multiple-definition \
    -Wl,--enable-auto-import -Wl,--whole-archive libThing.a \
    -Wl,--no-whole-archive [libs libThing uses internally]

That'll create Thing.dll and an import lib called Thing_mingw.lib.
Ignore Thing_mingw.lib, and create a new DMD-compatible import lib using:

     implib /system Thingdll.lib Thing.dll

(implib should be in the dm/bin dir)
--bb



More information about the Digitalmars-d mailing list