Results 1 to 6 of 6

Thread: really necessary to segregate the locations of static and shared versions of Qt?

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default really necessary to segregate the locations of static and shared versions of Qt?

    Recently I was editing the hints section of the building Qt statically on Linux page and I learnt a lot of things.

    I have raised a question there about whether it is really necessary to separate the install locations of static and shared versions of the Qt library, seeing as the linker has an option -static which forces it to use static libraries when available, thus overriding its behaviour of defaulting to shared libraries when both are found in the library path.

    Please elucidate the situation and correct the wiki page also accordingly, providing an answer to my question. Thank you.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  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: really necessary to segregate the locations of static and shared versions of Qt?

    On Linux it doesn't make much difference where are the libraries if you're sure the linker will take the one you want(*), but on Windows the library consists of two parts - the real dynamic object and a static stub linked to the application. The static library and stub for the dynamic version are named the same, so you can't keep them in the same directory.

    *) what happens if you want a shared build but a shared object is missing whereas a static one is present? The linker will try to use the static one, which is not what you want.

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

    jamadagni (18th April 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: really necessary to segregate the locations of static and shared versions of Qt?

    Quote Originally Posted by wysota View Post
    on Windows the library consists of two parts - the real dynamic object and a static stub linked to the application. The static library and stub for the dynamic version are named the same, so you can't keep them in the same directory.
    I don't fully understand. What is this stub thing? (Wikipedia did not help.)

    I thought that on Windows shared libs are present as dll files and static libs are present as lib files and the linking behaviour is the same as on Linux. From what you say, apparently this isn't true. Are you saying that libs are never static-linked on Windows and only some form of pseudo static-linking is done?

    what happens if you want a shared build but a shared object is missing whereas a static one is present? The linker will try to use the static one, which is not what you want.
    I will prevent this using the explicit -call_shared option. Won't that work?

    BTW is it possible to specify in the qmake build system which libraries to link static and which to link dynamic? I don't seem to see anything on this in the qmake reference.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  5. #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: really necessary to segregate the locations of static and shared versions of Qt?

    Quote Originally Posted by jamadagni View Post
    I don't fully understand. What is this stub thing? (Wikipedia did not help.)

    I thought that on Windows shared libs are present as dll files and static libs are present as lib files and the linking behaviour is the same as on Linux. From what you say, apparently this isn't true. Are you saying that libs are never static-linked on Windows and only some form of pseudo static-linking is done?
    No, I mean that even if you link your application dynamically, you need to link (statically) against a small .lib (or .a) file during compilation. Static linkage works as usual.


    I will prevent this using the explicit -call_shared option. Won't that work?
    Do you use that flag for every project of yours?

    BTW is it possible to specify in the qmake build system which libraries to link static and which to link dynamic? I don't seem to see anything on this in the qmake reference.
    No, it's the linker that decides what and how to link. The only portable thing you can do is to ask for static linkage which will prevent any libraries from being linked dynamically. If you want more, you have to use implementation-specific switches.

  6. #5
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: really necessary to segregate the locations of static and shared versions of Qt?

    Quote Originally Posted by wysota View Post
    Do you use that flag for every project of yours?
    Of course not. I was only discussing the possibilities.
    If you want more, you have to use implementation-specific switches.
    You mean switches to ld? Such as...?
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  7. #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: really necessary to segregate the locations of static and shared versions of Qt?

    Quote Originally Posted by jamadagni View Post
    You mean switches to ld? Such as...?
    I don't know... "any" switches...

Similar Threads

  1. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  2. shared versus static build
    By jcr in forum Installation and Deployment
    Replies: 2
    Last Post: 28th January 2006, 08:05

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.