Link with C static library
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jan 16 00:33:23 PST 2011
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
More information about the Digitalmars-d-learn
mailing list