www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Calling a non-mangled C function?

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
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?
Jan 02 2005
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
Neeevermind, found out I could do it with an IMPORTS directive in the .def
file.

WOW am I overjoyed :D
Jan 02 2005
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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.
Jan 02 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
 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..
Jan 02 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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

 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.
Jan 03 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
 _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.
Jan 03 2005