Search code examples
c++qtqt4qmakeqtcore

Using libraries in Qt


My questions may seems like it is a real duplicate, but however I checked many related questions, my problem still remains.

I found and compiled a project called SMTPEmail, so I have my .dll and .lib files under the directories Libraries/SMTPClient/debug and Libraries/SMTPClient/release.

enter image description here

When I try to include the header files in example in case of emailadress.h: #include <emailaddress.h> or #include <SMTPEmail/emailaddress.h>, I got the error Cannot open include file 'emailaddress.h'. The Q_DECL_EXPORT modifier is used in the header files.

SMTPEmail.pro:

...
QT       += core network

TARGET = SMTPEmail

TEMPLATE = lib

DEFINES += SMTP_BUILD

win32:CONFIG += dll

QMAKE_CXXFLAGS += -fPIC
...

MyProject.pro:

...

INCLUDEPATH += ./Libraries/SMTPClient/debug

DEPENDPATH += ./Libraries/SMTPClient/debug

win32:LIBS += ./Libraries/SMTPClient/debug/SMTPEmail.lib
...

I also tried:

LIBS += -L./Libraries/SMTPClient/debug/ -lSMTPEmail

and

LIBS += -L$$_PRO_FILE_PWD_/Libraries/SMTPClient/debug/ -lSMTPEmail

and

LIBS += -L$$PWD_/Libraries/SMTPClient/debug/ -lSMTPEmail

and

LIBS += -L./MyProject/Libraries/SMTPClient/release/ -lSMTPEmail

The only thing that I didn't do is copying or linking the header files which are inside the library to my app?

I have the strong feeling that I missed a small step somewhere, can you help me pointing out what I am doing wrong?


Solution

  • I think your problem is (at least) this line:

    INCLUDEPATH += ./Libraries/SMTPClient/debug
    

    I am almost certain that this is not the right path to the include path where the headers can be found including emailadress.h.

    You have explained the LIBS values that you have tried as well as the lib path in great length, but you are getting an include error from the compiler rather than a linkage problem with the libraries from the linker. I would suggest to figure out where the headers are located and add it to the include path as follows:

    # This is just pseudo code, but you need something like this
    INCLUDEPATH += $$PWD/Includes/SMTPClient
    

    Answering your question of:

    The only thing that I didn't to is copying the header files which should be inside the library, is that right?

    It depends on what you mean. If you mean whether the library should be self-contained, then the answer is no, unless you are using dynamic library loading with manual symbol resolution and the like, which I do not recommend for simple cases.

    If you mean, it is shipped with the project that you are trying to reuse, then sure, and that is why you would need to specify the includepath in your project to that path.