www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linking with/Debugging static C/C++ libraries

reply Jeff Slutter <MrMustard gmail.com> writes:
I'm just starting out in my journey of R&D/evaluation of using D, as a
possible future development platform, for my team at work. I like a lot
of what I see!

Currently we do all our development in Visual Studio, using C/C++ (and
C# for some tools), and it is definitely the 'comfort zone' for the
team. My goal is to reduce the learning curves, and new tools they'll
have to pick up. The Visual D project is of great interest to me.

One of the things that's important to us is being able to link against
some existing C/C++ static libraries (built with VS 2008, so PE COFF
format). In some light testing I was able to link a D2 project with a
C/C++ Static library project in VS/VisualD with DMD. I had to use the
objconv.exe tool, as the Digital Mars tool coff2omf.exe seems to be too
old to work with the newer MS generated libraries. Unfortunately, it
looks like objconv will always strip out debugging information, and
while I had successful link and execution, I could only debug the D
code, there was no debugging information for the C/C++ code.

I suppose if the C/C++ code was in a DLL and D referenced the import
lib, things would work much better, but there are some cases where our
applications really need to come as a single executable and not have
dependent DLLs along for the ride.

Am I missing some sort of process or tool to make this all happen how I
want? I want to be able to link C/C++ static libraries, generated with
Visual Studio, with DMD, and maintain debugging information. Yes, I
know, that is not a simple request. :)

For what it's worth, using GDC and GCC/MingW (TDM), I was able to build
and debug a D/C/C++ mixed executable. I had to use GDB (though WinGDB
works just dandy), but the downside is I'm not using Visual D (unless
Visual D supports GDC??), nor DMD. DMD seems that it would be more
supported and stable right now than GDC, which seems to play catch up. I
worry that, as a user of GDC, hitting a compiler bug, would take longer
to get an official fix for, than it would for DMD.

Thanks everyone...
Jeff
May 29 2011
parent reply Trass3r <un known.com> writes:
Am 30.05.2011, 04:09 Uhr, schrieb Jeff Slutter <MrMustard gmail.com>:
 One of the things that's important to us is being able to link against
 some existing C/C++ static libraries (built with VS 2008, so PE COFF
 format).

Good luck with that. DLLs are no problem but static libraries are another story. objconv has never done the job for me. I'm surprised that it worked in your test. And compiling the code with dmc is a real PITA. Maybe dmd will finally switch to COFF output in the course of 64Bit transition but even then the 2 different compilers might generate incompatible code. There is a linker named Unilink though, which is reportedly able to link OMF and COFF files out of the box. But it doesn't even have a homepage, only an ftp server that's hard to find. Plus it's closed source so you can't assess whether it will continue to be developed, if it becomes commercial one day etc.
 For what it's worth, using GDC and GCC/MingW (TDM), I was able to build
 and debug a D/C/C++ mixed executable. I had to use GDB (though WinGDB
 works just dandy), but the downside is I'm not using Visual D (unless
 Visual D supports GDC??), nor DMD. DMD seems that it would be more
 supported and stable right now than GDC, which seems to play catch up. I
 worry that, as a user of GDC, hitting a compiler bug, would take longer
 to get an official fix for, than it would for DMD.

GDC shares the frontend with dmd, so it will benefit from any FE bug fixed there. Regarding the glue code, it is currently maintained by Iain alone. He tends to be quite active though. OT: You are R&D and still use Windoze? ;)
May 30 2011
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 30.05.2011 16:57, Trass3r wrote:
 Am 30.05.2011, 04:09 Uhr, schrieb Jeff Slutter <MrMustard gmail.com>:
 One of the things that's important to us is being able to link against
 some existing C/C++ static libraries (built with VS 2008, so PE COFF
 format).

Good luck with that. DLLs are no problem but static libraries are another story. objconv has never done the job for me. I'm surprised that it worked in your test. And compiling the code with dmc is a real PITA. Maybe dmd will finally switch to COFF output in the course of 64Bit transition but even then the 2 different compilers might generate incompatible code. There is a linker named Unilink though, which is reportedly able to link OMF and COFF files out of the box. But it doesn't even have a homepage, only an ftp server that's hard to find. Plus it's closed source so you can't assess whether it will continue to be developed, if it becomes commercial one day etc.

It was me who brought it Unilink out of infernal abyss :) See also: http://www.digitalmars.com/d/archives/digitalmars/D/announce/Alternative_linker_win32_64_20086.html Seriously I still suggest to try it out, and at any rate author showed quite a motivation and provided full D support in no time. (there is little problem that he won't use CV debug symbols... and UniLink _converts_ them to Borland's TDS format) Still it's now possible to use any linker with VisualD, using 'compile only' option (in fact I just tried it out myself).
 For what it's worth, using GDC and GCC/MingW (TDM), I was able to build
 and debug a D/C/C++ mixed executable. I had to use GDB (though WinGDB
 works just dandy), but the downside is I'm not using Visual D (unless
 Visual D supports GDC??), nor DMD. DMD seems that it would be more
 supported and stable right now than GDC, which seems to play catch up. I
 worry that, as a user of GDC, hitting a compiler bug, would take longer
 to get an official fix for, than it would for DMD.

GDC shares the frontend with dmd, so it will benefit from any FE bug fixed there. Regarding the glue code, it is currently maintained by Iain alone. He tends to be quite active though.

Right and I've seen this cool option 'use other compiler' in recent VisualD with textbox for command line. So GDC & LDC support is almost there.
 OT: You are R&D and still use Windoze? ;)

-- Dmitry Olshansky
May 30 2011
parent reply Jeff Slutter <MrMustard gmail.com> writes:
On 5/30/2011 10:57 AM, Dmitry Olshansky wrote:
 It was me who brought it Unilink out of infernal abyss :)  See also:
 http://www.digitalmars.com/d/archives/digitalmars/D/announce/Alternative_linker_win32_64_20086.html
 
 
 Seriously I still suggest to try it out, and at any rate author showed
 quite a motivation and provided full D support in no time.
 (there is little problem that he won't use CV debug symbols... and
 UniLink _converts_ them to Borland's TDS format)
 Still it's now possible to use any linker with VisualD, using 'compile
 only' option (in fact I just tried it out myself).

I will give it a try. With the Borland TDS debug symbols, that means no debugging with VisualD/Visual Studio right? (No CodeView, No PDB)
 Right and I've seen this cool option 'use other compiler' in recent
 VisualD with textbox for command line. So GDC & LDC support is almost
 there.

I missed that, so that's exciting!
May 30 2011
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 30.05.2011 19:14, Jeff Slutter wrote:
 On 5/30/2011 10:57 AM, Dmitry Olshansky wrote:
 It was me who brought it Unilink out of infernal abyss :)  See also:
 http://www.digitalmars.com/d/archives/digitalmars/D/announce/Alternative_linker_win32_64_20086.html


 Seriously I still suggest to try it out, and at any rate author showed
 quite a motivation and provided full D support in no time.
 (there is little problem that he won't use CV debug symbols... and
 UniLink _converts_ them to Borland's TDS format)
 Still it's now possible to use any linker with VisualD, using 'compile
 only' option (in fact I just tried it out myself).

With the Borland TDS debug symbols, that means no debugging with VisualD/Visual Studio right? (No CodeView, No PDB)

For the sake of expreiment I did tested it with latest trial of CodeGear C++ Builder-something long ago. I even thought to tweak Mago debugger so that it reads TDS symbols. IIRC it has dedicated component for symbol loading. But with GSOC I think my hands are full for the rest of summer :)
 Right and I've seen this cool option 'use other compiler' in recent
 VisualD with textbox for command line. So GDC&  LDC support is almost
 there.


-- Dmitry Olshansky
May 30 2011