www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How do you use C based libs with D?

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
Hi, this is a bit related to my post regarding MingW compatibility.

As D uses Optilink (AFAIU) this implies that all C based code needs to 
be compiled with DMC?

Not that I don't like DMC (I like it a lot) but I always had problems 
(or it requires a bunch of work) to get open-source projects 
compileable with it.

How do you deal with this?

-- 
Robert M. Münch
http://www.robertmuench.de
Jun 11 2010
next sibling parent reply Adam Ruppe <destructionator gmail.com> writes:
It works without much hassle at all if you dynamically link the
library. That's what I do when using other people's C libs. (For my
own, I'll just recompile with dmc on Windows. On Linux, it just works,
since they all use the same linker anyway.)
Jun 11 2010
parent reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
On 2010-06-11 21:39:19 +0200, Adam Ruppe said:

 It works without much hassle at all if you dynamically link the
 library. That's what I do when using other people's C libs.

Hi, yes, that's the fallback. Either getting all this stuff as DLL already or having to make one. On the other hand I try to avoid "DLL hell" to keep the support costs as low as possible. -- Robert M. Münch http://www.robertmuench.de
Jun 11 2010
parent "Nick Sabalausky" <a a.a> writes:
"Robert M. Münch" <robert.muench robertmuench.de> wrote in message 
news:huu417$1pu9$1 digitalmars.com...
 On 2010-06-11 21:39:19 +0200, Adam Ruppe said:

 It works without much hassle at all if you dynamically link the
 library. That's what I do when using other people's C libs.

Hi, yes, that's the fallback. Either getting all this stuff as DLL already or having to make one. On the other hand I try to avoid "DLL hell" to keep the support costs as low as possible.

You could just bundle the correct DLL directly in with your exe, in the same directory. (Or convince the OSS devs to support DMC ;) )
Jun 11 2010
prev sibling next sibling parent Bane <branimir.milosavljevic gmail.com> writes:
Robert M. Münch Wrote:

 Hi, this is a bit related to my post regarding MingW compatibility.
 
 As D uses Optilink (AFAIU) this implies that all C based code needs to 
 be compiled with DMC?
 
 Not that I don't like DMC (I like it a lot) but I always had problems 
 (or it requires a bunch of work) to get open-source projects 
 compileable with it.
 
 How do you deal with this?

I deal the way you say: some compiles nice, some requires (lot) of work, and some are just impossible to compile, so I use dll. Is there particular reason you avoid using dll's?
 
 -- 
 Robert M. Münch
 http://www.robertmuench.de
 

Jun 11 2010
prev sibling parent Alex Makhotin <alex bitprox.com> writes:
Robert M. Münch wrote:
 Hi, this is a bit related to my post regarding MingW compatibility.
 
 As D uses Optilink (AFAIU) this implies that all C based code needs to 
 be compiled with DMC?
 
 Not that I don't like DMC (I like it a lot) but I always had problems 
 (or it requires a bunch of work) to get open-source projects compileable 
 with it.
 
 How do you deal with this?
 

Produce static libraries in mingw as usual(no need to recompile with DMC or other compiler). Produce shared library from these static libraries with mingw by linking all of them in one DLL. Apply implib tool on obtained DLL. Link obtained import library with the target. Place the DLL in the exact private folder where your executable resides to avoid DLL hell. -- Alex Makhotin, the founder of BITPROX, http://bitprox.com
Jun 11 2010