5 Attachment(s)
Problem with class type for dll
Hi All,
I have been trying to create a shared library using guidelines from the article https://doc.qt.io/qt-5/sharedlibrary.html :
Qt .pro :Attachment 13455
Code:
QT += qml quick core
TARGET = profile1
TEMPLATE = lib
DEFINES += PROFILE1_LIBRARY
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use 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 += \
profile1.cpp
HEADERS += \
profile1.h \
profile1_global.h
unix {
target.path = /usr/lib
INSTALLS += target
}
Main header :Attachment 13456
Code:
#ifndef PROFILE1_GLOBAL_H
#define PROFILE1_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(PROFILE1_LIBRARY)
# define PROFILE1SHARED_EXPORT Q_DECL_EXPORT
#else
# define PROFILE1SHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // PROFILE1_GLOBAL_H
Header :Attachment 13457
Code:
#ifndef PROFILE1_H
#define PROFILE1_H
#include "profile1_global.h"
class PROFILE1SHARED_EXPORT Profile1
{
public:
Profile1();
void func1();
};
#endif // PROFILE1_H
Code : Attachment 13458
Code:
#include "profile1.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
Profile1::Profile1()
{
}
I keep getting an error for class declaration : class PROFILE1SHARED_EXPORT Profile1 -" variable has incomplete type 'class Q_DECL_EXPORT' "
Thank you in advance for your help.
Re: Problem with class type for dll
According to the docs on creating shared libraries, you should be including "<QtCore/QtGlobal>", not "<QtCore/qglobal>".
Re: Problem with class type for dll
I have made the change "<QtCore/QtGlobal>"instead of"<QtCore/qglobal>" but nothing changed. I still get the same error. I have to mention that I am using a C++ compiler and the OS is Linux
Re: Problem with class type for dll
Well, yeah, if you look at the contents of QtGlobal, it is:
Code:
#include "qglobal.h"
:rolleyes:
But in any case, these export and import macros are only used for building Windows DLLs. They are not used on linux platforms, and are typically #define to be nothing, usually something like this:
Code:
#ifdef _WIN32 || _WIN64
#define Q_DECL_EXPORT __declspec(dllexport)
#define Q_DECL_IMPORT __declspec(dllimport)
#else
#define Q_DECL_EXPORT
#define Q_DECL_IMPORT
#endif
So in fact you don't need to put any type of declaration in front of your class names.
Re: Problem with class type for dll
Quote:
Originally Posted by
cleopa
I have to mention that I am using a C++ compiler and the OS is Linux
Posted code compiles and links as-is for me: Linux, GCC 9.3.0, Qt 5.12.8
Code:
chrisw@newton:/tmp/tt$ qmake
Info: creating stash file /tmp/tt/.qmake.stash
chrisw@newton:/tmp/tt$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DPROFILE1_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o profile1.o profile1.cpp
rm -f libprofile1.so.1.0.0 libprofile1.so libprofile1.so.1 libprofile1.so.1.0
g++ -Wl,-O1 -shared -Wl,-soname,libprofile1.so.1 -o libprofile1.so.1.0.0 profile1.o /usr/lib/x86_64-linux-gnu/libQt5Gui.so /usr/lib/x86_64-linux-gnu/libQt5Core.so /usr/lib/x86_64-linux-gnu/libGL.so -lpthread
ln -s libprofile1.so.1.0.0 libprofile1.so
ln -s libprofile1.so.1.0.0 libprofile1.so.1
ln -s libprofile1.so.1.0.0 libprofile1.so.1.0
I'd be trying a clean rebuild:
Code:
$ make distclean
$ qmake
$ make