Results 1 to 5 of 5

Thread: Help needed linking to library

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Help needed linking to library

    I have just started using Qt and would like to create an exe that calls functions in a dll. I have created a library as described here and now I am trying to call an exported function from a Qt GUI application. When I try to build the exe I get the following error:

    ../TestLibrary/testfuncs.h:13: error: function `QString testfunc()' definition is marked dllimport.

    I don't really understand this error because surely dllimport is what I want? Any advice would be appreciated.

  2. #2
    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: Help needed linking to library

    Did you export the symbols in the library correctly? When building the library the symbol should be declared as dllexport and when using it - as dllimport.
    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.


  3. #3
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help needed linking to library

    Quote Originally Posted by wysota View Post
    Did you export the symbols in the library correctly? When building the library the symbol should be declared as dllexport and when using it - as dllimport.
    I have the following in my library:

    Qt Code:
    1. #if defined(TESTLIB_LIBRARY)
    2. #define TESTLIB_EXPORT Q_DECL_EXPORT
    3. #else
    4. #define TESTLIB_EXPORT Q_DECL_IMPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. TESTLIB_EXPORT QString testfunc() { return "This is a test"; }
    To copy to clipboard, switch view to plain text mode 

    I have a DEFINES += TESTLIB_LIBRARY in the .pro file of the library. What is strange is if I comment out the conditional compilation so that TESTLIB_EXPORT is always defined as Q_DECL_EXPORT is seems to work. This doesn't make sense, because then surely it is not being specified as dllimport in the exe

  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: Help needed linking to library

    Your code is incorrect. testFunc() is defined in the header, it is part of the application that includes the header file so you can't dllimport it. Move the definition to the cpp file and it should work.
    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
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help needed linking to library

    Quote Originally Posted by wysota View Post
    Your code is incorrect. testFunc() is defined in the header, it is part of the application that includes the header file so you can't dllimport it. Move the definition to the cpp file and it should work.
    Thanks! That will teach me for trying to code it up quickly!

Similar Threads

  1. Replies: 0
    Last Post: 8th April 2009, 19:52
  2. Logger Library : advice and help needed.
    By Antoine in forum Qt Programming
    Replies: 6
    Last Post: 6th April 2007, 08:40
  3. Replies: 1
    Last Post: 5th March 2007, 20:50
  4. linking qt3 to a library
    By thebra in forum Newbie
    Replies: 10
    Last Post: 11th November 2006, 01:25
  5. import library linking
    By bruce1007 in forum Qt Programming
    Replies: 6
    Last Post: 19th May 2006, 10:27

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.