Results 1 to 18 of 18

Thread: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    I am attempting to build a simple dll hello world example. I have build qt 4.7.0 for static linking by doing this on the command line:
    Qt Code:
    1. C:\Qt\4.7.0> configure -static -release -no-exceptions -nomake examples -nomake demos
    2. C:\Qt\4.7.0> make sub-src
    To copy to clipboard, switch view to plain text mode 

    Here is my sample .pro file

    Qt Code:
    1. TEMPLATE = lib
    2. TARGET = helloworld
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. CONFIG += dll
    7.  
    8. # Input
    9. HEADERS += helloworld.h
    10. SOURCES += helloworld.cpp
    To copy to clipboard, switch view to plain text mode 

    here is my example helloworld.cpp

    Qt Code:
    1. #include "helloworld.h"
    2. #include <stdio.h>
    3.  
    4. HelloWorld::HelloWorld(QObject *parent) :
    5. QObject(parent)
    6. {
    7. }
    8.  
    9. void HelloWorld::sayHello() {
    10. printf("Hello World!\n");
    11. done();
    12. }
    To copy to clipboard, switch view to plain text mode 

    and the header...

    Qt Code:
    1. #ifndef HELLOWORLD_H
    2. #define HELLOWORLD_H
    3.  
    4. #include <QObject>
    5.  
    6. class HelloWorld : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit HelloWorld(QObject *parent = 0);
    11.  
    12. signals:
    13. void done();
    14.  
    15. public slots:
    16. void sayHello();
    17.  
    18. };
    19.  
    20. #endif // HELLOWORLD_H
    To copy to clipboard, switch view to plain text mode 

    when I try to compile as dll, I get the errors shown below. Any Ideas?


    Qt Code:
    1. C:\projects\qt\helloworld>qmake
    2. C:\projects\qt\helloworld>make release
    3. mingw32-make -f Makefile.Release
    4. mingw32-make[1]: Entering directory `C:/projects/qt/helloworld'
    5. g++ -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -shared -Wl,--out-implib,release\libh
    6. elloworld.a -o release\helloworld.dll release/helloworld.o release/moc_helloworld.o -L"c:\Qt\4.7.0\lib" -lQtGui -lgdi32 -lcomdlg32 -lo
    7. leaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
    8. Creating library file: release\libhelloworld.a
    9. release/helloworld.o:helloworld.cpp:(.text+0x16): undefined reference to `_imp___ZN7QObjectC2EPS_'
    10. release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x4d): undefined reference to `_imp___ZN7QObject11qt_metacastEPKc'
    11. release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x8e): undefined reference to `_imp___ZN11QMetaObject8activateEP7QObjectPKS_iPPv'
    12. release/moc_helloworld.o:moc_helloworld.cpp:(.text+0xb9): undefined reference to `_imp___ZN7QObject11qt_metacallEN11QMetaObject4CallEiP
    13. Pv'
    14. release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x100): undefined reference to `_imp___ZN7QObject16staticMetaObjectE'
    15. release/moc_helloworld.o:moc_helloworld.cpp:(.text$_ZN10HelloWorldD1Ev[HelloWorld::~HelloWorld()]+0x10): undefined reference to `_imp__
    16. _ZN7QObjectD2Ev'
    17. release/moc_helloworld.o:moc_helloworld.cpp:(.text$_ZN10HelloWorldD0Ev[HelloWorld::~HelloWorld()]+0x15): undefined reference to `_imp__
    18. _ZN7QObjectD2Ev'
    19. collect2: ld returned 1 exit status
    20. mingw32-make[1]: *** [release\helloworld.dll] Error 1
    21. mingw32-make[1]: Leaving directory `C:/projects/qt/helloworld'
    22. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Qt Code:
    1. C:\projects\qt\helloworld>qmake
    To copy to clipboard, switch view to plain text mode 

    That's the qmake from the static library?

  3. #3
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    That's the qmake I did from the test projects main directory.

  4. #4
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Did you run it before or after you added the Q_OBJECT macro to your class?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    The QObject Macro was added before I ran qmake. Does it make a difference?

  6. #6
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Did you remove the dynamic version of Qt before building the static one?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    I guess I can't be certain that I did. How do you remove the dynamic libs? Is there any easy way to do it now that I've built the static libs?

  8. #8
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    You delete them or build the static version in a different directory. Otherwise your projects might pick up the dynamic libraries instead of the static ones.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    I guess I was under the impression that the static build would be built in a different directory than the dynamic libraries. Could you point me at the dynamic libs? I'm not even sure where the static libs were put...I didn't pay too much attention to the paths during the build unfortunately.

  10. #10
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Then it will probably be a good lesson for you to try and find the libraries yourself. You'll learn something about Qt's directory layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    yeah okay, so in the root there is a bin directory with dll's in them and it looks like the static libs are in the lib/ directory. So they are in different directories.

  12. #12
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    dll files are not used during the compilation. The lib files are. Now imagine you have a mix of lib files from a static and dynamic build, draw the conclusions yourself

    By the way, I fail to see a practical use of a Qt-based dll compiled with static Qt libs. Would you enlighten me about your ultimate goal?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    In looking at the lib files, it looks like they all have modified dates of around the 2 hrs or so when I was building the static libs so I doubt that there is a mix.

    The idea for the Qt-based dll is to have to reduce the number of dlls that I have to distribute to co-workers. I created a dll that does some image manipulation that interfaces to some scripts I have written in Ruby. Qt was used because the image processing is much faster in Qt than in other ruby libs that we could find. Maybe it's simpler if I just distribute the QtCore4.dll (and any other dlls needed) with my custom dll. I was hoping to only have to distribute only one file (and by distribute I mean check in to the project on svn). Not everyone has Qt installed on their machine so that is another reason I was hoping to use a static build.

  14. #14
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    I don't know what you intend to do later but so far you are exposing Qt interface to the outside world so programs that want to use your library would have to link against Qt as well. There are ruby bindings for Qt (or is it Qt bindings for Ruby? Whatever...) available, maybe that will be a more suitable solution for you - you wouldn't have to touch any C++ code at all.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. The following user says thank you to wysota for this useful post:

    kvb (7th November 2010)

  16. #15
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Well it turns out that adding the line DEFINES += QT_NODLL to my .pro file got rid of all my issues...I swear I tried that before and it didn't work.

    exposing Qt interface to the outside world so programs that want to use your library would have to link against Qt as well
    I'm afraid I don't understand this statement, isn't the purpose of doing the static build suppose to get you away from having to link against qt in other applications? Maybe I'm just too confused to be helped...

    I will look into the ruby bindings, they could be really usefull. Thanks for pointing those out!

  17. #16
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Quote Originally Posted by kvb View Post
    I'm afraid I don't understand this statement, isn't the purpose of doing the static build suppose to get you away from having to link against qt in other applications? Maybe I'm just too confused to be helped...
    If you expose things such as "QObject" then code that is to use it has to know about QObject as well. It's not enough to link to code that knows QObject. If you only expose functions with an interface that has no relation to Qt (so you don't deliver any header files containing QString, QObject or QWhatEverElseGoesHere) then you are fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #17
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Thanks for clarification...I am exposing the dll with C style functions (no relation to Qt).

    I looked quickly at the ruby bindings and it looks like its using Qt 4.3 and ruby 1.8.6 and I'm using ruby 1.9.2...bummer.

    Thanks for your help!

  19. #18
    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: Tons of unresolved externals when building a dll and statically built Qt 4.7.0

    Quote Originally Posted by kvb View Post
    I looked quickly at the ruby bindings and it looks like its using Qt 4.3 and ruby 1.8.6 and I'm using ruby 1.9.2...bummer.
    You can probably build the bindings for newer Qt and newer Ruby as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Configuring Qt fow Wince (QtNetwork4.dll unresolved externals)
    By southerton in forum Installation and Deployment
    Replies: 0
    Last Post: 1st October 2010, 11:16
  2. Replies: 2
    Last Post: 31st October 2009, 03:41
  3. Is it recommended to statically built Qt?
    By RThaden in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2008, 20:23
  4. Unresolved externals
    By MarkoSan in forum General Programming
    Replies: 3
    Last Post: 17th March 2007, 13:53
  5. What am I missing? Unresolved externals
    By derick in forum Qt Programming
    Replies: 49
    Last Post: 21st July 2006, 12:41

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.