DMC to Create C .lib ?

Sergey Gromov snake.scaly at gmail.com
Fri Mar 27 06:40:09 PDT 2009


Fri, 27 Mar 2009 00:18:47 -0400, Chris Andrews wrote:

> Sergey Gromov Wrote:
> 
>> You're talking about Doryen Library project, right?
>> 
>> My thought is that TCOD_console_flush is actually cdecl and must be
>> declared as extern(C), while you seem to declare it as extern(Windows)
>> which is stdcall.  What you get with linkdef is corrupted stack.  This
>> is why coffimplib is absolute best when you have the right COFF import
>> library: it allows to catch this sort of errors.
> 
> Hah, you got me.  Yeah, I'm toying with a wrapper for Doryen Library
> in D.  I'm trying to not talk too much about it, since I don't know
> if I'm skilled enough to write and implement it, nor dedicated enough
> to finish it. :p  We'll see. 

I just wanted to double-check that you did the conversion correctly.  So
I ended up finding out what the hell TCOD was.  Sorry for the spoiler!
:D

> All the methods were preprended by TCODLIB_API, which is a typedef to
> __declspec(dllexport) ( or __declspec(import) ) which I thought
> (according to the guide) translates as export extern(Windows) 

__declspec(dllexport) just directs the compiler to make this function
available from outside your DLL.  It does not change calling convention.
It's equivalent to just "export" in D.

By default, C uses "cdecl" calling convention ("extern(C)" in D), and
C++ uses "fastcall", I think ("extern(C++)" in D).  C++ also uses cdecl
if explicitly told so via 'extern "C" { ...' construct, usually
somewhere in a header with function prototypes.

Since every calling convention uses different mangling rules (symbol
naming) you can usually tell them apart: functions with simple names
with "_" prepended are cdecl, funky long names are fastcall, simple
names with @num are stdcall (extern(Windows), extern(System)).

> I guess I'll try externing to C instead, and try to coffimp the
> library again.  Perhaps the "visual studio" library is a bad one to
> use, and I should try the "Mingw" .a file.

Visual Studio library should be perfectly fine.

P.S.
This post really belongs to D.learn.



More information about the Digitalmars-d mailing list