Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 50

Thread: What am I missing? Unresolved externals

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    src/corelib/global/qglobal.h:# define Q_DECL_EXPORT __declspec(dllexport)

    Qt Code:
    1. #ifndef Q_DECL_EXPORT
    2. # ifdef Q_OS_WIN
    3. # define Q_DECL_EXPORT __declspec(dllexport)
    4. # elif defined(QT_VISIBILITY_AVAILABLE)
    5. # define Q_DECL_EXPORT __attribute__((visibility("default")))
    6. # endif
    7. # ifndef Q_DECL_EXPORT
    8. # define Q_DECL_EXPORT
    9. # endif
    10. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by wysota
    src/corelib/global/qglobal.h:# define Q_DECL_EXPORT __declspec(dllexport)

    Qt Code:
    1. #ifndef Q_DECL_EXPORT
    2. # ifdef Q_OS_WIN
    3. # define Q_DECL_EXPORT __declspec(dllexport)
    4. # elif defined(QT_VISIBILITY_AVAILABLE)
    5. # define Q_DECL_EXPORT __attribute__((visibility("default")))
    6. # endif
    7. # ifndef Q_DECL_EXPORT
    8. # define Q_DECL_EXPORT
    9. # endif
    10. #endif
    To copy to clipboard, switch view to plain text mode 
    And where's __declspec(dllimport)?

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by jacek
    And where's __declspec(dllimport)?
    I didn't say there is.

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by wysota
    I didn't say there is.
    But in this case it's useless.

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by jacek
    But in this case it's useless.
    Not quite...

    You can always redefine that macro (which doesn't change the fact that a need for such thing at all is just stupid) before including headers.

    Qt Code:
    1. #ifdef Q_OS_WIN
    2. # ifdef Q_DECL_EXPORT
    3. # undef Q_DECL_EXPORT
    4. # endif
    5. # define Q_DECL_EXPORT __declspec(dllimport)
    6. #endif
    7. #include "somefile.h"
    8. #undef Q_DECL_EXPORT
    To copy to clipboard, switch view to plain text mode 

    Anyway my point was that Qt helps a little with defining those macros. It helps source code to be more portable. I didn't say it (unfortunately) releases the user from knowing that OS-dependent little magic tricks.

  6. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by wysota
    Not quite...

    You can always redefine that macro (which doesn't change the fact that a need for such thing at all is just stupid) before including headers.
    [...]
    Anyway my point was that Qt helps a little with defining those macros. It helps source code to be more portable.
    So Qt provides an undocumented macro that you must redefine to able to use it. Well... I wouldn't call it helpfull.

  7. #27
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by jacek
    Probably nowhere, it's specific only to windows DLLs --- normal systems doesn't require this.
    "normal systems". So I can make plugins for Windows which arn't dlls? I just want plugins to work on Windows - I don't care how!

  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by Paul Drummond
    "normal systems". So I can make plugins for Windows which arn't dlls? I just want plugins to work on Windows - I don't care how!
    What Jacek meant was that well written systems don't require those macros, while Windows does

  9. #29
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by jacek
    Where?
    I believe it's Q_EXPORT (or at least it was in Qt3).

    Then you define -D QT_DLL or -D QT_NODLL depending on whether you are linking with a dll or a static library.
    Save yourself some pain. Learn C++ before learning Qt.

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by Chicken Blood Machine
    I believe it's Q_EXPORT (or at least it was in Qt3).
    Yes it was in Qt3, but is there something similar in Qt4?

  11. #31
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by jacek
    Yes it was in Qt3, but is there something similar in Qt4?
    I've just checked my ported Qt4 code and I seem to be using Q_DECL_EXPORT
    Save yourself some pain. Learn C++ before learning Qt.

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by Chicken Blood Machine
    I've just checked my ported Qt4 code and I seem to be using Q_DECL_EXPORT
    OK, so there is Q_DECL_EXPORT and Q_DECL_IMPORT which are set correctly. The only missing thing is a single macro which will be set to Q_DECL_EXPORT or Q_DECL_IMPORT depending on whether you build DLL or application that uses it.

    Something like this:
    Qt Code:
    1. #ifdef QT_DLL
    2. # define EXPORT Q_DECL_EXPORT
    3. #else
    4. # define EXPORT Q_DECL_IMPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 7th March 2006 at 22:11. Reason: changed QT_PLUGIN to QT_DLL

  13. #33
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Correct me if i'm wrong - but as far as i can tell, Q_DECL_EXPORT and Q_DECL_IMPORT are the macros used by Qt when building a plugin. From an aesthetic viewpoint you should use your own when building an off-the-shelf dynamic library.

    If i want to build an dynamic library (let's call it mylib), i include the following header called MyLibDef.h in every class header file whose interface i want to be exported to the dll.
    Qt Code:
    1. #ifndef MY_LIBDEF_H_
    2. #define MY_LIBDEF_H_
    3.  
    4. #if defined(WIN32)
    5. # ifdef MY_LIB_DLL
    6. # define MY_LIB_DLLMAPPING __declspec(dllexport)
    7. # else
    8. # define MY_LIB_DLLMAPPING __declspec(dllimport)
    9. # endif
    10. #else
    11. # define MY_LIB_DLLMAPPING
    12. #endif
    13.  
    14. #endif
    To copy to clipboard, switch view to plain text mode 
    The class declarationt then looks like this:
    Qt Code:
    1. class MY_LIB_DLLMAPPING Foo : public QWidget
    2. ...
    To copy to clipboard, switch view to plain text mode 
    I then add the -D MY_LIB_DLL to the compiler flags when i compile the dll. When i use the headers in some app that links the library the MY_LIB_DLL is not set by default and everything is fine.

    Cutting-and-pasting-and-replacing MY_LIB with something other takes approximately 30 seconds - IMHO this ain't that much

    Regarding the WIN32 symbol: I don't use qmake so it might be that WIN32 will not work but you can replace it with the symbol Q_OS_WIN spotted in one of the posts above.

  14. #34
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by orb9
    Correct me if i'm wrong - but as far as i can tell, Q_DECL_EXPORT and Q_DECL_IMPORT are the macros used by Qt when building a plugin. From an aesthetic viewpoint you should use your own when building an off-the-shelf dynamic library.

    If i want to build an dynamic library (let's call it mylib), i include the following header called MyLibDef.h in every class header file whose interface i want to be exported to the dll.
    Qt Code:
    1. #ifndef MY_LIBDEF_H_
    2. #define MY_LIBDEF_H_
    3.  
    4. #if defined(WIN32)
    5. # ifdef MY_LIB_DLL
    6. # define MY_LIB_DLLMAPPING __declspec(dllexport)
    7. # else
    8. # define MY_LIB_DLLMAPPING __declspec(dllimport)
    9. # endif
    10. #else
    11. # define MY_LIB_DLLMAPPING
    12. #endif
    13.  
    14. #endif
    To copy to clipboard, switch view to plain text mode 
    The class declarationt then looks like this:
    Qt Code:
    1. class MY_LIB_DLLMAPPING Foo : public QWidget
    2. ...
    To copy to clipboard, switch view to plain text mode 
    I then add the -D MY_LIB_DLL to the compiler flags when i compile the dll. When i use the headers in some app that links the library the MY_LIB_DLL is not set by default and everything is fine.

    Cutting-and-pasting-and-replacing MY_LIB with something other takes approximately 30 seconds - IMHO this ain't that much

    Regarding the WIN32 symbol: I don't use qmake so it might be that WIN32 will not work but you can replace it with the symbol Q_OS_WIN spotted in one of the posts above.

    I agree completely. This should probably be put in an FAQ for people coming over from the UNIX world.

    I'm currently working with Windows dlls at work and I have to say I hate the crappy implementation that MS has. On unix, you generally don't even need to know whether you are linking with a shared library or an archive library and you don't need any 'clever' macros when writing the interface for a library either. OK - rant over - don't bother responding to this
    Save yourself some pain. Learn C++ before learning Qt.

  15. #35
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Ok, I made some progress:

    When I tried to build the mySQL plugin it just did not work. The n I rebuilt my whole Qt from source (not using qt-win-commercial-4.1.0-vs2003.exe) and it magically worked.

    For the moment I use this in my PRO file and it works:
    Qt Code:
    1. #Settings:
    2. QT += qt3support xml sql
    3. QT -= gui
    4. #CONFIG += dll
    5. CONFIG += staticlib
    6. #DEFINES += BUILD_DLL
    7. #DLLDESTDIR = ../xpaf
    8. DESTDIR = ../xpaf
    9. TEMPLATE = lib
    10. #Settings end
    To copy to clipboard, switch view to plain text mode 

    I'll revert back to DLLs soon and see how it goes.
    Derick Schoonbee

  16. #36
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by Chicken Blood Machine
    I'm currently working with Windows dlls at work and I have to say I hate the crappy implementation that MS has. On unix, you generally don't even need to know whether you are linking with a shared library or an archive library and you don't need any 'clever' macros when writing the interface for a library either. OK - rant over - don't bother responding to this
    I don't like the dark side, too... but this time part of their stuff isn't that bad.
    The __declspec(dllexport) directive tells the compiler to explicitly export the class from the DSO. This enables tuning of a DSO interface, which results in smaller compiled code, improved loading time, etc. This feature (even better is available in >=gcc-3.4, too. See
    http://gcc.gnu.org/wiki/Visibility
    for more infos.

  17. #37
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals - SOLVED

    One of my problems:
    My MS Visual Studio project files got overwritten by the Qt VS integration plugin making that the librarian skips my moc_*.obj files as the output directory changed.

    Thanks to this thread:
    http://www.qtcentre.org/forum/showthread.php?t=450
    Last edited by derick; 19th February 2006 at 12:43.
    Derick Schoonbee

  18. #38
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by orb9
    I don't like the dark side, too... but this time part of their stuff isn't that bad.
    The __declspec(dllexport) directive tells the compiler to explicitly export the class from the DSO. This enables tuning of a DSO interface, which results in smaller compiled code, improved loading time, etc. This feature (even better is available in >=gcc-3.4, too. See
    http://gcc.gnu.org/wiki/Visibility
    for more infos.
    Hmm, I wasn't aware of that. You learn something new every day! Thanks for the info.
    Save yourself some pain. Learn C++ before learning Qt.

  19. #39
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    I'm sorry, but can someone please explain to me why all this isn't explained in the Qt documentation? When reading about plugins and QLibrary, the Troll's should state if the code won't work on a particular platform. If I developed a plugin in Linux I would expect it to work on all supported platforms WITHOUT CODE CHANGES. I would accept configuration and compilation issues, but this is a code modification which isn't acceptable IMO.

  20. #40
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by Paul Drummond
    I'm sorry, but can someone please explain to me why all this isn't explained in the Qt documentation?
    It isn't?
    On Windows you must also explicitly export the function from the DLL using the __declspec(dllexport) compiler directive, for example:
    extern "C" MY_EXPORT int avg(int a, int b)
    {
    return (a + b) / 2;
    }
    with MY_EXPORT defined as
    #ifdef Q_WS_WIN
    #define MY_EXPORT __declspec(dllexport)
    #else
    #define MY_EXPORT
    #endif
    Well... one might expect that this should be placed in different parts of the documentation too, but you can't say it isn't explained

    Anyway, the Trolls are responsible for the documentation, so you should ask them, not users of this forum.

Similar Threads

  1. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  2. shared vs static
    By alisami in forum Installation and Deployment
    Replies: 3
    Last Post: 4th October 2008, 13:04
  3. Replies: 16
    Last Post: 23rd May 2008, 10:12
  4. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 16:06
  5. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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.