Thread overview
Calling a non-mangled C function?
Nevermind
Jan 02, 2005
Stewart Gordon
Jan 03, 2005
Walter
January 02, 2005
I have a lib that was compiled in C, and the names are NOT mangled.  So no _Function@4, just Function.

How do I call this from D?  In my D code, I have the line:

extern (C) Function(int whatever);

and when I link, the linker likes the library, but my program's obj file is looking for _Function@4, when it should be looking for an unmangled name.

How on earth can I get it to look for the unmangled name?


January 02, 2005
Neeevermind, found out I could do it with an IMPORTS directive in the .def file.

WOW am I overjoyed :D


January 02, 2005
Jarrett Billingsley wrote:
<snip>
> extern (C) Function(int whatever);

What happened to the return type?  Should this compile?

> and when I link, the linker likes the library, but my program's obj file is
> looking for _Function@4, when it should be looking for an unmangled name.

This looks like a bug to me.

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on on the 'group where everyone may benefit.
January 02, 2005
> What happened to the return type?  Should this compile?

I just typed the code, didn't copy and paste ;)  I realized that there was no return type after I posted it, but there is no Edit Post function here, and I figured no one would really notice..

> This looks like a bug to me.

Maybe not a bug, but an oversight.  Perhaps Walter didn't know that it was possible to have unmangled names..?  Anyway, it was a very simple fix (in my def file, all I had to put was an IMPORTS _Function@4=<libname>.Function).

Still, would be nice to not have to do that, though I'm not sure how it'd translate from the matching C++ code that generated the lib - "extern "C" __declspec(dllexport)".  I though that "extern (C) export" would do it, but apparently not..


January 03, 2005
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:cr9807$2ntf$1@digitaldaemon.com...
> I have a lib that was compiled in C, and the names are NOT mangled.  So no _Function@4, just Function.
>
> How do I call this from D?  In my D code, I have the line:
>
> extern (C) Function(int whatever);
>
> and when I link, the linker likes the library, but my program's obj file
is
> looking for _Function@4, when it should be looking for an unmangled name.
>
> How on earth can I get it to look for the unmangled name?

_Function@4 is mangled with the:
    extern (Windows)
mangling.


January 03, 2005
> _Function@4 is mangled with the:
>     extern (Windows)
> mangling.

My bad.  But using extern(C) still doesn't help the problem - then it looks
for _Function.