Results 1 to 5 of 5

Thread: Problem with class type for dll

  1. #1
    Join Date
    Aug 2019
    Posts
    4
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default 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 :profile1.pro

    Qt Code:
    1. QT += qml quick core
    2.  
    3.  
    4. TARGET = profile1
    5. TEMPLATE = lib
    6.  
    7. DEFINES += PROFILE1_LIBRARY
    8.  
    9. # The following define makes your compiler emit warnings if you use
    10. # any feature of Qt which has been marked as deprecated (the exact warnings
    11. # depend on your compiler). Please consult the documentation of the
    12. # deprecated API in order to know how to port your code away from it.
    13. DEFINES += QT_DEPRECATED_WARNINGS
    14.  
    15.  
    16.  
    17. # You can also make your code fail to compile if you use deprecated APIs.
    18. # In order to do so, uncomment the following line.
    19. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    20. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    21.  
    22. SOURCES += \
    23. profile1.cpp
    24.  
    25. HEADERS += \
    26. profile1.h \
    27. profile1_global.h
    28.  
    29. unix {
    30. target.path = /usr/lib
    31. INSTALLS += target
    32. }
    To copy to clipboard, switch view to plain text mode 



    Main header
    :profile1_global.h

    Qt Code:
    1. #ifndef PROFILE1_GLOBAL_H
    2. #define PROFILE1_GLOBAL_H
    3.  
    4. #include <QtCore/qglobal.h>
    5.  
    6.  
    7. #if defined(PROFILE1_LIBRARY)
    8. # define PROFILE1SHARED_EXPORT Q_DECL_EXPORT
    9. #else
    10. # define PROFILE1SHARED_EXPORT Q_DECL_IMPORT
    11. #endif
    12.  
    13. #endif // PROFILE1_GLOBAL_H
    To copy to clipboard, switch view to plain text mode 

    Header :profile1.h

    Qt Code:
    1. #ifndef PROFILE1_H
    2. #define PROFILE1_H
    3.  
    4.  
    5. #include "profile1_global.h"
    6.  
    7.  
    8. class PROFILE1SHARED_EXPORT Profile1
    9. {
    10.  
    11. public:
    12.  
    13. Profile1();
    14. void func1();
    15.  
    16. };
    17.  
    18.  
    19. #endif // PROFILE1_H
    To copy to clipboard, switch view to plain text mode 



    Code : profile1.cpp

    Qt Code:
    1. #include "profile1.h"
    2. #include <stdio.h>
    3. #include <string.h>
    4. #include <unistd.h>
    5. #include <fcntl.h>
    6.  
    7.  
    8. Profile1::Profile1()
    9. {
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 




    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.
    Attached Images Attached Images
    Last edited by cleopa; 28th May 2020 at 18:05.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with class type for dll

    According to the docs on creating shared libraries, you should be including "<QtCore/QtGlobal>", not "<QtCore/qglobal>".
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    cleopa (28th May 2020)

  4. #3
    Join Date
    Aug 2019
    Posts
    4
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default 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

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with class type for dll

    Well, yeah, if you look at the contents of QtGlobal, it is:

    Qt Code:
    1. #include "qglobal.h"
    To copy to clipboard, switch view to plain text mode 




    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:

    Qt Code:
    1. #ifdef _WIN32 || _WIN64
    2. #define Q_DECL_EXPORT __declspec(dllexport)
    3. #define Q_DECL_IMPORT __declspec(dllimport)
    4. #else
    5. #define Q_DECL_EXPORT
    6. #define Q_DECL_IMPORT
    7. #endif
    To copy to clipboard, switch view to plain text mode 

    So in fact you don't need to put any type of declaration in front of your class names.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    cleopa (28th May 2020)

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem with class type for dll

    Quote Originally Posted by cleopa View Post
    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
    Qt Code:
    1. chrisw@newton:/tmp/tt$ qmake
    2. Info: creating stash file /tmp/tt/.qmake.stash
    3.  
    4. chrisw@newton:/tmp/tt$ make
    5. 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
    6. rm -f libprofile1.so.1.0.0 libprofile1.so libprofile1.so.1 libprofile1.so.1.0
    7. 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
    8. ln -s libprofile1.so.1.0.0 libprofile1.so
    9. ln -s libprofile1.so.1.0.0 libprofile1.so.1
    10. ln -s libprofile1.so.1.0.0 libprofile1.so.1.0
    To copy to clipboard, switch view to plain text mode 

    I'd be trying a clean rebuild:
    Qt Code:
    1. $ make distclean
    2. $ qmake
    3. $ make
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. What is Type information when creating Class
    By vinothrajendran in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2015, 13:11
  2. 'CLASS' does not name a type
    By plopes21 in forum General Programming
    Replies: 4
    Last Post: 27th August 2013, 04:42
  3. Replies: 10
    Last Post: 1st May 2011, 19:27
  4. 'Class' does not name a type error
    By naturalpsychic in forum Qt Programming
    Replies: 9
    Last Post: 1st February 2011, 16:43
  5. Determine Class Type of QObject Parent
    By photo_tom in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2010, 18:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.