views:

50

answers:

1

Greetings all,

I use MinGW,QT and CMake for my project.

http://i34.tinypic.com/30w85xt.png

As shown in the figure, my project has two modules.

  1. libRinzoCore.DLL - a shared library which define some abstract classes and interfaces and some core functionality of the application.This module is used to implement dynamic Plugins (which are also shared libraries which automatically loaded by the application) .

  2. Rinzo.exe - the main application.This uses "libRinzoCore" classes.

"libRinzoCore" mainly developed using QT objects and link against the QT library.

"Rinzo.exe" also uses QT library objects,some are not being used in "libRinzoCore".So I have to link QT Library and "libRinzoCore" with this executable.

I can compile "libRinzoCore" without problems and it generated two files "libRinzoCore.DLL" and "libRinzoCore.DLL.a"

But during compiling "Rinzo.exe" it gives the following output :

Linking CXX executable Rinzo.exe
Info: resolving IRzPlugin::staticMetaObject       by linking to __imp___ZN9IRzPlugin16staticMetaObjectE (auto-import)
Info: resolving IRzViewerPlugin::staticMetaObject        by linking to __imp___ZN15IRzViewerPlugin16staticMetaObjectE (auto-import)
Info: resolving IRzLayeringPlugin::staticMetaObject        by linking to __imp___ZN17IRzLayeringPlugin16staticMetaObjectE (auto-import)
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols
 from auto-imported DLLs.
[100%] Built target Rinzo

And when executing "Rinzo.exe" it crashes with the message (this is a translation from Japanese error message)

" Application cannot performe correctly (0xc0000005). Click [OK] to cancel "

Here are my CMake files for

libRinzoCore :

http://www.keepandshare.com/doc/2199086/rinzocore-txt-august-31-2010-12-10-pm-2k?da=y

Rinzo.exe :

http://www.keepandshare.com/doc/2199085/rinzo-txt-august-31-2010-12-10-pm-5k?da=y

It works fine,If I compile "libRinzoCore" as a static-library. And works fine on Linux.

Any tips?

+2  A: 

On windows you need to declare "export" part of dynamic library to make it work.

#ifdef Q_WS_WIN
#ifdef RINZO_EXPORT
#define RINZO_LIB __declspec(dllexport)
#else
#define RINZO_LIB __declspec(dllimport)
#endif
#else
#define RINZO_LIB
#endif

Then you need to put RINZO_LIB in front of your class declaration inside of lib (only classess you want to "export", use in external code)

class RINZO_LIB YourExportedClass
{
...
}

Last part is to add preprocessor macro while compiling your library. As you can see it's RINZO_EXPORT

Remember, don't add this preprocessor macro, when "importing" (using code outside library).

Also all functions require RINZO_LIB macro to be visible outside library:

RINZO_LIB void yourExportedFunction()
{
...
}
Kamil Klimek
Thanks alot Kamil.You saved my day!!!!
umanga