www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Link with C static library

reply alvinsay <alvinsay gmail.com> writes:
Hi,

Is it possible for D language to link with C static library under win32
platform?

Because visual studio produce COFF fomrat, I try to use coff2omf to convert
libraries build by vs2008. However, it seems that coff2omf doesn't support
static library.
Should I change my C compiler? Or, there is another way to covert static
library from COFF to OMF??
Jan 16 2011
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday 16 January 2011 00:14:56 alvinsay wrote:
 Hi,
 
 Is it possible for D language to link with C static library under win32
 platform?
 
 Because visual studio produce COFF fomrat, I try to use coff2omf to convert
 libraries build by vs2008. However, it seems that coff2omf doesn't support
 static library. Should I change my C compiler? Or, there is another way to
 covert static library from COFF to OMF??
optlink is not compatible with Microsoft's linker. So, unless you can somehow convert from one format to another, you can't use C code with D code which has been compiled by a Microsoft compiler. However, if you use dmc to compile your C code, then it links just fine, since it uses optlink as its linker, just like dmd does. Apparently, linking against dlls somehow avoids the COFF vs OMF problem, so that would be another way to get around the problem: use a dll for the C code. Regardless, the fact that optlink unfortunately uses a different format than Microsoft's compiler means that you can normally link to C code on Windows unless you have all of the source code and can compile it yourself with dmc. Maybe someone else knows of a good library format converter though. - Jonathan M Davis
Jan 16 2011
prev sibling next sibling parent novice2 <sorry noem.ail> writes:
 Is it possible for D language to link with C static library under win32
platform?
yes, imho, it is possible. i successfully tried such thing with dev-cpp + gcc + coff2omf. btw, coff2omf.exe says: COFF to OMF Object Module Conversion Utility, Version 1.00.195 Copyright (C) 1994 by Walter Oney All rights reserved
Jan 16 2011
prev sibling parent reply Trass3r <un known.com> writes:
 Should I change my C compiler? Or, there is another way to covert static  
 library from COFF to OMF??
coff2omf should work, but unfortunately it isn't free. coffimplib is free, but can only convert import libraries. You may try to use objconv: http://www.agner.org/optimize/#objconv Though it doesn't work in all cases. Compiling with dmc solves the issue but is often tedious cause headers are different etc. Easiest solution if you can't do it statically is to use dlls.
Jan 16 2011
parent reply alvinsay <alvinsay gmail.com> writes:
 coff2omf should work, but unfortunately it isn't free.
Actually, I downloaded coff2omf from ftp.digitalmars.com. I used it to convert static library, and it says the input library is not import library. Is that the same version as what you mentioned non-free version?
 coffimplib is free, but can only convert import libraries.
 You may try to use objconv: http://www.agner.org/optimize/#objconv
 Though it doesn't work in all cases.
 Compiling with dmc solves the issue but is often tedious cause headers are
 different etc.
 Easiest solution if you can't do it statically is to use dlls.
Many existing C libraries are not written as dynamic libraries. Some C libraries can be compiled as DLL, but in performance critical application, such as games, they must use static link to increase performance. I hope there is a good solution for linking C static libraries.
Jan 16 2011
parent Trass3r <un known.com> writes:
 I used it to convert static library, and it says the input library is  
 not import library.
That's coffimplib. coff2omf is in the Extended Utilities Package which is sold for 15$.
 Many existing C libraries are not written as dynamic libraries. Some C  
 libraries can be
 compiled as DLL, but in performance critical application, such as games,  
 they must use
 static link to increase performance. I hope there is a good solution for  
 linking C static libraries.
Well maybe Walter will give away coff2omf (and maybe obj2asm too) for free some day to solve this problematic situation. As I said, either you buy coff2omf, try objconv or compile with dmc.
Jan 16 2011