By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

DLLs using MinGW

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Ernesto" <eb*****@hotmail.com> wrote...
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
Jul 22 '05 #2

P: n/a
Ernesto wrote:
[...]
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
Jul 22 '05 #3

P: n/a

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
Jul 22 '05 #4

P: n/a
Victor Bazarov wrote:
"Ernesto" <eb*****@hotmail.com> wrote...
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.


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.

--
Mike Smith
Jul 22 '05 #5

P: n/a
Ryan Mitchley wrote:
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).

--
Mike Smith
Jul 22 '05 #6

P: n/a
Mike Smith wrote:
[...]
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
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.