www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Re: QtD 0.1 is out!

reply Eldar Insafutdinov <e.insafutdinov gmail.com> writes:
Can somebody help me with exporting functions from a DLL? I am defining
functions in C++ like
extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
After compiling a DLL with MINGW and producing a lib file for it with implib I
am trying to use them from D.
In D I declare them as
extern (C) void* __qtd_QObject_QObject_QObject(args);
And then compile it and link it to the .lib file made by implib for that DLL,
but optlink complains that symbol is undefined. I tried to use that Cfunction
from C++ and it worked. What I can do?
Feb 12 2009
next sibling parent reply Bill Baxter <wbaxter gmail.com> writes:
On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov
<e.insafutdinov gmail.com> wrote:
 Can somebody help me with exporting functions from a DLL? I am defining
functions in C++ like
 extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
 After compiling a DLL with MINGW and producing a lib file for it with implib I
am trying to use them from D.
 In D I declare them as
 extern (C) void* __qtd_QObject_QObject_QObject(args);
 And then compile it and link it to the .lib file made by implib for that DLL,
but optlink complains that symbol is undefined. I tried to use that Cfunction
from C++ and it worked. What I can do?

What's the implib command you're using? Often you need to use the /system flag. --bb
Feb 12 2009
next sibling parent Eldar Insafutdinov <e.insafutdinov gmail.com> writes:
Bill Baxter Wrote:

 On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov
 <e.insafutdinov gmail.com> wrote:
 Can somebody help me with exporting functions from a DLL? I am defining
functions in C++ like
 extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
 After compiling a DLL with MINGW and producing a lib file for it with implib I
am trying to use them from D.
 In D I declare them as
 extern (C) void* __qtd_QObject_QObject_QObject(args);
 And then compile it and link it to the .lib file made by implib for that DLL,
but optlink complains that symbol is undefined. I tried to use that Cfunction
from C++ and it worked. What I can do?

What's the implib command you're using? Often you need to use the /system flag. --bb

Thanks, that helped! I used it without any flags.
Feb 12 2009
prev sibling parent Eldar Insafutdinov <e.insafutdinov gmail.com> writes:
Bill Baxter Wrote:

 On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov
 <e.insafutdinov gmail.com> wrote:
 Can somebody help me with exporting functions from a DLL? I am defining
functions in C++ like
 extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
 After compiling a DLL with MINGW and producing a lib file for it with implib I
am trying to use them from D.
 In D I declare them as
 extern (C) void* __qtd_QObject_QObject_QObject(args);
 And then compile it and link it to the .lib file made by implib for that DLL,
but optlink complains that symbol is undefined. I tried to use that Cfunction
from C++ and it worked. What I can do?

What's the implib command you're using? Often you need to use the /system flag. --bb

okay, second problem then - I need to be able to call extern (C) functions defined in D code from DLL. I tried to do getProcAddress(NULL, "__some_D_func"); but this doesn't work.
Feb 12 2009
prev sibling next sibling parent Bill Baxter <wbaxter gmail.com> writes:
On Fri, Feb 13, 2009 at 5:00 AM, Eldar Insafutdinov
<e.insafutdinov gmail.com> wrote:
 Bill Baxter Wrote:

 On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov
 <e.insafutdinov gmail.com> wrote:
 Can somebody help me with exporting functions from a DLL? I am defining
functions in C++ like
 extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
 After compiling a DLL with MINGW and producing a lib file for it with implib I
am trying to use them from D.
 In D I declare them as
 extern (C) void* __qtd_QObject_QObject_QObject(args);
 And then compile it and link it to the .lib file made by implib for that DLL,
but optlink complains that symbol is undefined. I tried to use that Cfunction
from C++ and it worked. What I can do?

What's the implib command you're using? Often you need to use the /system flag. --bb

okay, second problem then - I need to be able to call extern (C) functions defined in D code from DLL. I tried to do getProcAddress(NULL, "__some_D_func"); but this doesn't work.

I think you may have to write some code to explicitly register your D functions with the DLL. You could write a mini getDCodeProcAddress kind of thing in your D code. Then give a pointer to that function to the C code in the DLL at startup. Then C code uses getDCodeProcAddress from there. Maybe there's an easier way, but that's what I'd try. --bb
Feb 12 2009
prev sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Thu, 12 Feb 2009 22:22:41 +0300, Eldar Insafutdinov  
<e.insafutdinov gmail.com> wrote:

 Can somebody help me with exporting functions from a DLL? I am defining  
 functions in C++ like
 extern "C" __declspec(dllexport) void*  
 __qtd_QObject_QObject_QObject(args)
 After compiling a DLL with MINGW and producing a lib file for it with  
 implib I am trying to use them from D.
 In D I declare them as
 extern (C) void* __qtd_QObject_QObject_QObject(args);
 And then compile it and link it to the .lib file made by implib for that  
 DLL, but optlink complains that symbol is undefined. I tried to use that  
 Cfunction from C++ and it worked. What I can do?

I believe it should be extern extern(C) ... Otherwise you /declare/ a function with C linkage but provide no implementation so that's why it fails at link time.
Feb 13 2009