Unsolved Error Linking Visual Studio DLL to Qt
-
Hi All,
I have written a project in visual studio that I would like to use within Qt as a dll. The project cosists of a class and several additional c++ files that are not part of the class. Within the class I use the functions that are found in the additional files.
Ideally I would like to export only the class and use it as a dll within Qt but I'm encountering some difficulries.
I've manged to export/link/include all the relevent files from visual studio to Qt but every time the class uses one of the functions found in the additinal files the program crashes. Initially, I thought there must be something wrong with my dll but it works perfectly when I try to load it to a similar program in visual studio.
I use MVSC in both Visual Studio and Qt, and used __dllexport only on the class defenition itself. Any ideas what I might be doing wrong?
Thanks in advance,
Yuval -
Hi and welcome to devnet,
The export/import declaration is a bit more complex than that.
Please take a look at the creating shared library guide in Qt's documentation. The concept applies also to standard C++ projects with some minor adjustments.
-
Thanks for the quick reply. I've tried adding the following lines to all the h files in my VS project:
#ifdef PROJECT_LIB
#define PROJECT_EXPORT __declspec(dllexport)
#else
#define PROJECT_EXPORT __declspec(dllimport)
#endifin addition, I've added the following line to my Qt pro files:
DEFINES += PROJECT_LIBI'm still geting the same behavior. Any advice?
-
@yuvalg1987 said in Error Linking Visual Studio DLL to Qt:
in addition, I've added the following line to my Qt pro files:
You must define PROJECT_LIB only when building the lib, not when using it
-
Ok. not sure what I did exactly but it works! Thanks for the help!