Results 1 to 20 of 30

Thread: Static and Dynamic Libraries

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 69 Times in 67 Posts

    Default Re: Static and Dynamic Libraries

    The syntax is the same. The .a library basically contains object code similar or equal to the .o files created during compilation. The dll (or shared object) is actually very similar to an executable. When you run your application, the compile time linked shared object will have to be in the search path, which on windows will typically be the application directory. Whether QLibrary can load it or not depends a bit on how you use it. You'll have to elaborate there what you want and what you are doing right now.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  2. The following user says thank you to franz for this useful post:

    waynew (24th November 2010)

  3. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Static and Dynamic Libraries

    Thanks franz. That helps. I tried linking the static library but it gives me a linker error( a reference error to the library function I call), not recognizing the first function call I make to the library. Yes, I have the headers included. Also, if I comment out the library function call, the build is ok, but the exe stays the same size, which indicates to me the library is not being included.

    So, I tried using the dll. I put it in my application build directory and included the headers. the build is ok, but QLibrary says it can't load the library. Dependency walker only shows a few warnings regarding Microsoft dlls.

    Also, if I pick a random MS dll and put it in my application build directory, QLibrary loads it ok.

    At this point, I am thinking there must be something wrong with my library (I built it from source using Mingw/msys).

  4. #3
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: Static and Dynamic Libraries

    Whatever you're building now and trying to link to the library will have to be built using the same tools the library was built with - mingw. It may have to be rebuilt to use similar flags - for example, you can't link a library built in 64-bit mode with an application built in 32-bit mode.

  5. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Static and Dynamic Libraries

    Thanks Six, I built the library on the same 32 bit Windows machine I made my Qt application on.
    So, that should not be a problem, right?

  6. #5
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: Static and Dynamic Libraries

    It may not be the problem, at least if they were built with the same compiler. Post the actual error message you're getting.

  7. #6
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Static and Dynamic Libraries

    Well, when I try to link to the static library, the error message is:
    C:\CPP\QT_Projects\HRLogger_Development/lotwupload.cpp:23: undefined reference to `_imp__tqsl_init@0'

    For reference, the pro file entry is:
    Qt Code:
    1. INCLUDEPATH += C:\mingw\msys\1.0\home\wayne\tqsllib\include
    2. LIBS += -L"C:\mingw\msys\1.0\home\wayne\tqsllib\lib" -ltqsllib
    To copy to clipboard, switch view to plain text mode 

    The library .h files are included in my application.

    And the first library call (where it fails) is :
    Qt Code:
    1. int ret = tqsl_init();
    To copy to clipboard, switch view to plain text mode 

    And this function is defined in tqsllib.h which is included in my application.

    So what could I be doing wrong here?

  8. #7
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 47 Times in 43 Posts

    Default Re: Static and Dynamic Libraries

    Hi ,
    Open the Makefile of ur project, see LIBS + line
    if double quotes is missing in pro file,
    Try LIBS += -L$$quote("C:\mingw\msys\1.0\home\wayne\tqsllib\lib ")

    or

    may be u can try by adding the library's path in the PATH variable. u can also try path in QtCreator's projects->Run Settings

    Try run qmake , clean & compile the project entirely

    hope it helps

    Thnks
    Bala
    Last edited by BalaQT; 25th November 2010 at 06:39.

  9. #8
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 69 Times in 67 Posts

    Default Re: Static and Dynamic Libraries

    Forward slashes. If possible, always use forward slashes.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  10. #9
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Static and Dynamic Libraries

    Thanks folks, tried that stuff, no luck. Same problem.
    If I comment out the call to the library function, and do a build, both with and without the LIBS lines in the pro file, the size of the application exe does not change.

    Does anyone else think this is an indicator that the library is not included in the exe? And that would cause the linker error when the library function call is left in?

  11. #10
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: Static and Dynamic Libraries

    For whatever reason, the linker is not able to locate the library you're trying to link to. It may be a quoting or backslash issue, as others have suggested, or simply a case of the library not where you're telling the linker to look for it. Check your path, make sure the library is really there and that the path it's on matches the one in your project file.

  12. #11
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Static and Dynamic Libraries

    Ok, I checked all of that and it is ok.

    Here is where part of my newbie confusion comes in. The doc for building the tqsllib says to use the configure command with --disable-shared, which I did. Then it says after running "make install" "This should result in the creation of the tqsllib2.dll" Which it did.

    Wouldn't using --disable-shared mean that you are creating a static library? Like a lib.a file? If so, then why does it create a dll?
    It also creates the files libtqsllib.a libtqsllib.la and tqsllibd.a in the lib directory where I built it. tqsllib2.dll is in the bin directory.

    I have been trying to use the tqsllib.a file as a static library. Is this incorrect?

    Can someone explain this to me? I am really library confused.
    At least I was able to build the qserialdevice static library and include it in my application and it is working fine. But this library is just not the same.

  13. #12
    Join Date
    Sep 2010
    Posts
    145
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 18 Times in 17 Posts

    Default Re: Static and Dynamic Libraries

    Looks like your answer lies here:
    Qt Code:
    1. #if defined(__WIN32__) && !defined(TQSL_NODLL)
    2. #ifdef TQSLLIB_DEF
    3. #define DLLEXPORT __stdcall __declspec(dllexport)
    4. #define DLLEXPORTDATA __declspec(dllexport)
    5. #else
    6. #define DLLEXPORT __stdcall __declspec(dllimport)
    7. #define DLLEXPORTDATA __declspec(dllimport)
    8. #endif
    9. #else
    10. #define DLLEXPORT
    11. #define DLLEXPORTDATA
    12. #endif
    To copy to clipboard, switch view to plain text mode 

    You aren't defining any of these symbols yourself are you?
    C:\CPP\QT_Projects\HRLogger_Development/lotwupload.cpp:23: undefined reference to `_imp__tqsl_init@0
    Here, the linker expects to find a function with the stdcall convention. It seems that you build the library one way, and you are trying to link against it in other.

    Examine your defines for building it, and check your defines for linkage.

Similar Threads

  1. Static or Dynamic !!
    By salmanmanekia in forum Newbie
    Replies: 7
    Last Post: 5th June 2010, 16:24
  2. Resources in dynamic libraries
    By seneca in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2009, 18:26
  3. Dynamic link libraries
    By nareshqt in forum Qt Programming
    Replies: 6
    Last Post: 22nd April 2008, 07:20
  4. having both static and dynamic libraries?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2007, 08:33
  5. Hot to define the directory for the dynamic libraries?
    By Dark_Tower in forum Qt Programming
    Replies: 5
    Last Post: 28th December 2006, 23:15

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
  •  
Qt is a trademark of The Qt Company.