1

I am trying to build a project using Windows 10 and Qt5.12. The small program is using the smtp protocol available here. I can confirm that on my Windows I have the OpenSSL 1.1.1c 28 May 2019. On my Ubuntu 19.04 the same exact program compiles and run as usual but not on Windows.

I am attaching below a print screen of the errors; however those are mostly of two types:

1) inconsistent dll linkage

2) definition of dllimport static data member not allowed

errors

Following this link it seems that Windows needs its "own" include (i.e. #include <windows....) however in my case the smtp library from the above link does not have any #include <windows> and don't know if they have to be generated. It seems they don't from the post I found

In addition I was reading this post too because I thought I could be useful but no information was useful to help me sort out the problem

I dug more and actually went to where the windows includes are and the following is the path I was able to find, but don't know if that could be useful:

includes

From all the posts I red the problem seems to be, in this specific case for Windows on how the .pro file is written. Below my .pro file. Note that I cloned this repository into my windows 10.

.pro

QT += quick quickcontrols2 concurrent network core gui

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

TARGET = SMTPEmail
TEMPLATE = lib
DEFINES += SMTP_BUILD
win32:CONFIG += dll


# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
        main.cpp \
        progressbardialog.cpp \
        robot.cpp \
        robotmanager.cpp \
        settings/emailaddress.cpp \
        settings/mimeattachment.cpp \
        settings/mimecontentformatter.cpp \
        settings/mimefile.cpp \
        settings/mimehtml.cpp \
        settings/mimeinlinefile.cpp \
        settings/mimemessage.cpp \
        settings/mimemultipart.cpp \
        settings/mimepart.cpp \
        settings/mimetext.cpp \
        settings/quotedprintable.cpp \
        settings/smtpclient.cpp \
        user.cpp \
        usermanager.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

HEADERS += \
    progressbardialog.h \
    robot.h \
    robotmanager.h \
    settings/SmtpMime \
    settings/emailaddress.h \
    settings/mimeattachment.h \
    settings/mimecontentformatter.h \
    settings/mimefile.h \
    settings/mimehtml.h \
    settings/mimeinlinefile.h \
    settings/mimemessage.h \
    settings/mimemultipart.h \
    settings/mimepart.h \
    settings/mimetext.h \
    settings/quotedprintable.h \
    settings/smtpclient.h \
    settings/smtpexports.h \
    user.h \
    usermanager.h

EDITS

To be even more specific it seems that every header the offending line is the following below:

class SMTP_EXPORT EmailAddress : public QObject // <-- SMTP_EXPORT

which leads to the smtpexports.h which I copied below:

#ifndef SMTPEXPORTS_H
#define SMTPEXPORTS_H

#ifdef SMTP_BUILD
#define SMTP_EXPORT Q_DECL_EXPORT
#else
#define SMTP_EXPORT Q_DECL_IMPORT
#endif

#endif // SMTPEXPORTS_H

ADDITIONAL EDITS

Almost all error are solved after adding DEFINES += SMTP_BUILD but I have two errors left and I added a print screen below:

error

Thank you very much for pointing in the right direction on how to solve this problem.

Emanuele
  • 2,194
  • 6
  • 32
  • 71
  • did you define `SMTP_BUILD` when you build the lib? – Thomas Dec 10 '19 at 15:07
  • @Thomas, thank you very much for reading the question. I am not a `Windows` user as I mainly use `Ubuntu`. So I guess the answer is no. How do I do that? I only `git clone` the folder and try to run it. – Emanuele Dec 10 '19 at 15:13
  • [this](https://github.com/bluetiger9/SmtpClient-for-Qt/commit/a4f4235139635bb375152950e6d852b4bbb38868) indicates that maybe you did. – Thomas Dec 10 '19 at 15:17
  • or maybe it doesn't. it lookes like you are not going through the lib but added the source files. then you prob. need to add the `DEFINES += SMTP_BUILD` line to your `.pro` file. – Thomas Dec 10 '19 at 15:23
  • as done [here](https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v1.1/SMTPEmail.pro) – Thomas Dec 10 '19 at 15:27
  • I followed your advice and got rid of almost all the errors. I only have left two errors. I updated the question adding **ADDITIONAL EDITS**. Thanks for your help so far – Emanuele Dec 10 '19 at 15:41
  • I also updated the code I posted on the question with the modifications – Emanuele Dec 10 '19 at 15:44
  • i think you need to ask a new question. feel free to accept my answer. I'm not sure that the `win32:CONFIG += dll` is right for your usecase. – Thomas Dec 10 '19 at 15:50
  • Thank you I just asked a [new question](https://stackoverflow.com/questions/59271296/qt5-windows-windows-cannot-find-executable). – Emanuele Dec 10 '19 at 16:09

1 Answers1

3

The files are designed to be compiled with the define SMTP_BUILD set where the source is added, either to a library or to an executable. You have to add the

DEFINES += SMTP_BUILD

to your pro file.

Thomas
  • 4,980
  • 2
  • 15
  • 30