Dynamic library in windows
Hi
I want to make dynamic library on windows
I using qt creator 2.4 and msvc 2010
In qmake i write this commands
Code:
QT -= core gui
TEMPLATE = lib
CONFIG += dll
Project build without issues but in in build directory i found only .dll file without .lib file
( I need from this .lib to link to this .dll )
What im doing wrong ???
Re: Dynamic library in windows
Does your code export any symbols? It's possible that there will be no import library if there are no exported symbols to import. See Creating Shared Libraries. I get an import library when I do a trivial example using the MingW tools (I don't have MSVC handy) but GCC exports by default.
Does this simple example do what you expect?
Code:
// Pro file
TEMPLATE = lib
QT -= core gui
CONFIG += dll
DEFINES += MYSHAREDLIB_LIBRARY
SOURCES += mysharedlib.cpp
// mysharedlib.h
#include <QtCore/QtGlobal>
#if defined(MYSHAREDLIB_LIBRARY)
# define MYSHAREDLIB_EXPORT Q_DECL_EXPORT
#else
# define MYSHAREDLIB_EXPORT Q_DECL_IMPORT
#endif
MYSHAREDLIB_EXPORT int doSomethingInsightful();
class MYSHAREDLIB_EXPORT ExportedClass {
ExportedClass();
int doSomething();
};
// mysharedlib.cpp
#include "mysharedlib.h"
int doSomethingInsightful()
{
return 42;
}
ExportedClass::ExportedClass()
{
}
int ExportedClass::doSomething()
{
return 0;
}
Re: Dynamic library in windows
Thanks
Is it possible for some one that not use Qt ,Qt creator or qmake to use
this library build in that way
Re: Dynamic library in windows
Yes, as long as the DLL does not link to any Qt component. The above uses macros defined by Qt headers but you could easily produce a non-Qt version of those macros to provide complete independence.
With the C++ example the user would have to be using the same compiler/linker type to cope with name mangling: e.g. if you built the DLL with MSVC they would need to use MSVC, if you build with MinGW/GCC they would need to use GCC.
If the interface is C-style then any compiler/linker should be able to use it.