Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved] qmake: build a dll and its .lib for MSVC
Dear QT gurus, I'm trying to build (with msvc) a dynamic library and would like to import it in another project compiled with Microsoft Visual C++ too.
@TEMPLATE = lib
CONFIG += dll
TARGET = mylib
VERSION = 1.0@
I searched across different forums and did find that I should add QMAKE_LFLAGS += /IMPLIB:mylib.lib my .pro file.
People say that it just need the /implib switch to be present in the link command line of the MSVC project.
Could someone confirm that I am doing this right?
Thanks a lot.
dword last edited by
Doing juste /implib generate a bad command line for the linker (at least not usable since it creates a file name 'u' or something like that). Specifying the export lib name: QMAKE_LFLAGS += /IMPLIB:mylib.lib works fine.
Ok thanks for the clarification.
Erm ... huh?
Isn't the most portable way the default one? With QMake there's no difference when linking libraries/dlls with gcc or msvc.
Just adding a new lib directory with
@LIBS += -L../myfancydll/debug@
and linking it with
@LIBS += -lmyfancydll@
With LIBS you specify the libraries that your project will link against.
This is not what I wanted to do.
I just read the description
[quote author="neFAST" date="1303579517"]Dear QT gurus, I'm trying to build (with msvc) a dynamic library and would like to import it in another project compiled with Microsoft Visual C++ too.[/quote]
And there the "normal way" is in the dynamic library:
Doing exports by defining a MYFANCYDLL_EXPORTS which defines MYFANCYDLL_API to either __declspec(dllimport) or __declspec(dllexport).
And linking this one in the application which is using the dynamic lib with:
LIBS += -LC:\mysources\myfancydll -lmyfancydll
If you're doing something special I may have misunderstood your question. I've never needed the /implib thing for anything :)
Ok maybe the sentence was not clear (but dword undestood)
Ok I want to import this lib in another project, and I already know how to do that.
But I need to export it first when building the dll.
Ok, but you know how the symbols are exported?
---- If you don't know: ----
In the dll project, create a "exports.h" (or call it whatever you like)
It should have the following contents:
define MYFANCYDLL_API __declspec(dllexport)
define MYFANCYDLL_API __declspec(dllimport)
In your myfancydll.pro, add
@DEFINES += MYFANCYDLL_EXPORTS@
Every class which should be exported should be written like the following:
class MYFANCYDLL_API MyExportedClass
When writing this way, a .lib file will be generated automatically, there's also no need for creating a .def file. By the way: Qt does the linkage the same way, see the Q_GUI_EXPORT in every QtGui class definition.
If you already know this stuff, just ignore this reply :)