www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linking libraries that are written in C++ with a C interface

reply "Gerry" <gerryw compvia.com> writes:
Hello All,

I'm trying to link a library that is written in C++ that provides 
a C interface. Unfortunately the lib is proprietary, so I can't 
include the code. I'm getting undefined references to new and 
delete operators etc.  This links fine with gcc. I'm using the 
following command line to build.

dmd test.d file1.d file2.d -L/path/to/lib/lib.a

Is this the write way to link a static library? I was actually 
using ldc, but couldn't get that to work at all.

Thanks,
-G
Jun 08 2014
parent reply "Gerry" <gerryw compvia.com> writes:
On Monday, 9 June 2014 at 01:47:57 UTC, Gerry wrote:
 Hello All,

 I'm trying to link a library that is written in C++ that 
 provides a C interface. Unfortunately the lib is proprietary, 
 so I can't include the code. I'm getting undefined references 
 to new and delete operators etc.  This links fine with gcc. I'm 
 using the following command line to build.

 dmd test.d file1.d file2.d -L/path/to/lib/lib.a

 Is this the write way to link a static library? I was actually 
 using ldc, but couldn't get that to work at all.

 Thanks,
 -G
Looks like the issue is related to linking a static lib not C++. Shared lib links fine. Had to use gdc to do it though. Thanks, -G
Jun 08 2014
parent reply Paul O'Neil <redballoon36 gmail.com> writes:
Do you need to link to a C++ runtime library?  That might be expected to 
be dynamic even if you compile a static C++ library.

Paul

On 06/08/2014 10:12 PM, Gerry wrote:
 On Monday, 9 June 2014 at 01:47:57 UTC, Gerry wrote:
 Hello All,

 I'm trying to link a library that is written in C++ that provides a C
 interface. Unfortunately the lib is proprietary, so I can't include
 the code. I'm getting undefined references to new and delete operators
 etc.  This links fine with gcc. I'm using the following command line
 to build.

 dmd test.d file1.d file2.d -L/path/to/lib/lib.a

 Is this the write way to link a static library? I was actually using
 ldc, but couldn't get that to work at all.

 Thanks,
 -G
Looks like the issue is related to linking a static lib not C++. Shared lib links fine. Had to use gdc to do it though. Thanks, -G
Jun 08 2014
parent "Gerry" <gerryw compvia.com> writes:
On Monday, 9 June 2014 at 02:39:36 UTC, Paul O'Neil wrote:
 Do you need to link to a C++ runtime library?  That might be 
 expected to be dynamic even if you compile a static C++ library.

 Paul

 On 06/08/2014 10:12 PM, Gerry wrote:
 On Monday, 9 June 2014 at 01:47:57 UTC, Gerry wrote:
 Hello All,

 I'm trying to link a library that is written in C++ that 
 provides a C
 interface. Unfortunately the lib is proprietary, so I can't 
 include
 the code. I'm getting undefined references to new and delete 
 operators
 etc.  This links fine with gcc. I'm using the following 
 command line
 to build.

 dmd test.d file1.d file2.d -L/path/to/lib/lib.a

 Is this the write way to link a static library? I was 
 actually using
 ldc, but couldn't get that to work at all.

 Thanks,
 -G
Looks like the issue is related to linking a static lib not C++. Shared lib links fine. Had to use gdc to do it though. Thanks, -G
Right! That makes perfect sense. Please forgive me for failing to see the forest for the trees. All good now. Thanks a million, -G
Jun 08 2014