View Full Version : Dynamic library in windows
themean
25th April 2012, 13:18
Hi
I want to make dynamic library on windows
I using qt creator 2.4 and msvc 2010
In qmake i write this commands
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 ???
ChrisW67
26th April 2012, 00:22
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?
// 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;
}
themean
26th April 2012, 18:32
Thanks
Is it possible for some one that not use Qt ,Qt creator or qmake to use
this library build in that way
ChrisW67
27th April 2012, 01:41
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 (http://en.wikipedia.org/wiki/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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.