DLLs using MinGW

E

Ernesto

Hi everybody:

I do not know if this is the right newsgroup for my issue, but I think
that someone here knows about this issue:

I am developing a set of libraries in C++ and I want to export my
classes into a .DLL using MinGW32. I know that I am able to export C
symbols but I'm not sure if class structures can be exported.

In Visual C++, I can use the __declspec(dllexport) and
__declspec(dllimport) class attributes to allow export (or import)
classes to/from DLLs. How can I do same stuff in mingw32???

If it is possible, the generated DLL will be linked to any application
compiled using MSVC++ or MinGW or the Borland C++ compiler, by
instance?

Thanks in advance



Ernesto
 
V

Victor Bazarov

Ernesto said:
I do not know if this is the right newsgroup for my issue, but I think
that someone here knows about this issue:

I am developing a set of libraries in C++ and I want to export my
classes into a .DLL using MinGW32. I know that I am able to export C
symbols but I'm not sure if class structures can be exported.

In Visual C++, I can use the __declspec(dllexport) and
__declspec(dllimport) class attributes to allow export (or import)
classes to/from DLLs. How can I do same stuff in mingw32???

If it is possible, the generated DLL will be linked to any application
compiled using MSVC++ or MinGW or the Borland C++ compiler, by
instance?

I only have an answer to your last question (and even it contains some
kind of a disclaimer): in _my_experience_ compilers are not even compatible
at the binaries level from version to version, even less so from vendor
to vendor. Some, however, do claim object file compatibility, like Intel
to MS. But nothing like MinGW to MS or to Borland or vice versa.

Victor
 
D

Denis Remezov

Ernesto said:
[...]

I am developing a set of libraries in C++ and I want to export my
classes into a .DLL using MinGW32. I know that I am able to export C
symbols but I'm not sure if class structures can be exported.

In Visual C++, I can use the __declspec(dllexport) and
__declspec(dllimport) class attributes to allow export (or import)
classes to/from DLLs. How can I do same stuff in mingw32???
[...]

I'm not sure about that (and it's too compiler/platfrom-specific
anyway), but, FWIW, consider an alternative:

Declare a pure abstract base class X (all pure virtual functions,
no data). Provide an implementation of class XImpl: public X in the
shared library. Provide a factory function "X* createXInstance()"
(that one can be easily exported) to be called by the client.
The destruction is by a virtual member function or by reference
counting, and so on and so on, variations are certainly possible.

Compared to class exporting, this approach means looser coupling
between dynamic/shared modules, and, I think, is more portable.
Of course you will still run into trouble if your modules use
incompatible ABIs in regards to virtual table layout and calling
conventions, and, unfortunately, you won't know it until run-time.
Still I think that class exporting is somewhat overrated.

Denis
 
R

Ryan Mitchley

VB> I only have an answer to your last question (and even it contains some
VB> kind of a disclaimer): in _my_experience_ compilers are not even
VB> compatible at the binaries level from version to version, even less so
VB> from vendor to vendor. Some, however, do claim object file
VB> compatibility, like Intel to MS. But nothing like MinGW to MS or to
VB> Borland or vice versa.

I've linked .a (library) files generated by MinGW successfully using MSVC++.
It didn't seem to be too difficult, as I remember. You may need to use
stdcall convention, but it's been a while and the memory is a little hazy.

Ryan
 
M

Mike Smith

Victor said:
I only have an answer to your last question (and even it contains some
kind of a disclaimer): in _my_experience_ compilers are not even compatible
at the binaries level from version to version, even less so from vendor
to vendor.

Getting more off-topic, but FWIW, in my thus far limited experience with
VS.NET 2003, its generated DLLs are interoperable with VC++6 code,
including exported C++ classes.
 
M

Mike Smith

Ryan said:
VB> I only have an answer to your last question (and even it contains some
VB> kind of a disclaimer): in _my_experience_ compilers are not even
VB> compatible at the binaries level from version to version, even less so
VB> from vendor to vendor. Some, however, do claim object file
VB> compatibility, like Intel to MS. But nothing like MinGW to MS or to
VB> Borland or vice versa.

I've linked .a (library) files generated by MinGW successfully using MSVC++.
It didn't seem to be too difficult, as I remember. You may need to use
stdcall convention, but it's been a while and the memory is a little hazy.

For C functions this will work, yes. It will not work for exported C++
classes (I've tried).
 
V

Victor Bazarov

Mike said:
[...]
Getting more off-topic, but FWIW, in my thus far limited experience with
VS.NET 2003, its generated DLLs are interoperable with VC++6 code,
including exported C++ classes.

I'd be very surprised if it didn't (bad business practice, really) but
I've seen it happen. The whole point is since the Standard doesn't
require it, no guarantees can be given. Hell, no guarantees can be
given even for what Standard does require...

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top