View mode: basic / threaded / horizontal-split · Log in · Help
February 25, 2008
D not able to link .o files
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
February 25, 2008
Re: D not able to link .o files
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.
February 25, 2008
Re: D not able to link .o files
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
February 25, 2008
Re: D not able to link .o files
Bill Baxter wrote:
> 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

I have never seen implib in either the dmd zip or dmc
February 26, 2008
Re: D not able to link .o files
Jacob Carlborg wrote:
> Bill Baxter wrote:
>> 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
> 
> I have never seen implib in either the dmd zip or dmc

Oops.  Maybe you need to get the "Basic Utilities Package" then.

I should read my README.txt more closely next time ;-).  There I clearly 
state:
"""
Next you need to create a D-compatible import lib from that using
'implib' in the "Basic Utilties Package":
http://www.digitalmars.com/download/freecompiler.html
--> http://ftp.digitalmars.com/bup.zip
"""

:-)

--bb
February 26, 2008
Re: D not able to link .o files
Bill Baxter wrote:
> Jacob Carlborg wrote:
>> Bill Baxter wrote:
>>> 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
>>
>> I have never seen implib in either the dmd zip or dmc
> 
> Oops.  Maybe you need to get the "Basic Utilities Package" then.
> 
> I should read my README.txt more closely next time ;-).  There I clearly 
> state:
> """
> Next you need to create a D-compatible import lib from that using
> 'implib' in the "Basic Utilties Package":
> http://www.digitalmars.com/download/freecompiler.html
> --> http://ftp.digitalmars.com/bup.zip
> """
> 
> :-)
> 
> --bb

There they are, that will make a lot of things easier :)
February 26, 2008
Re: D not able to link .o files
thx for answering

i will try it
February 26, 2008
Re: D not able to link .o files
another information is written here.

http://www.digitalmars.com/d/1.0/faq.html#omf
Top | Discussion index | About this forum | D home