Is it possible to link dynamic library /usr/lib64 while making static libraries of Qt



  • Why do I have put linker flags for X libraries in my Makefile when integrating static libQtGui and libQtCore

    0
    down vote
    favorite
    When I make static libraries of Qt (libQtCore.a and libQtGui.a) using following steps

    1. cd to path for qt-x11-commercial-src-4.3.3
    2. setenv PATH /pathto-qt-x11-commercial-src-4.3.3/bin:$PATH
    3. gmake confclean
    4. ./configure -release -static -largefile -qt3support -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -glib -platform linux-g++-64 -confirm-license -no-openssl -no-qdbus -prefix ./static_new -prefix-install -opengl -sm -L/usr/lib64 -lSM -lICE -xshape -lX11 -xinerama -lXinerama -xcursor -lXcursor -xfixes -lXfixes -xrandr -lXrandr -xrender -lXrender -fontconfig -lfontconfig -tablet -lXi -xkb -glib -lglib-2.0 -lXext
    5. gmake
      6 gmake install
      then I have to explicitly put following lines in my makefile to link X libraries in my final executable

    SLIBS += SM ICE Xi Xrender Xfixes Xrandr Xcursor Xinerama freetype Xext z gthread-2.0 glib-2.0 QtGui QtCore fontconfig
    otherwise I get undefined reference for symbols in above X libraries.

    But when I make shared libraries of libQtGui.so and libQtCore.so using following steps

    1. cd to path for qt-x11-commercial-src-4.3.3
    2. setenv PATH /pathto-qt-x11-commercial-src-4.3.3/bin:$PATH
    3. gmake confclean
    4. configure -release -shared -largefile -qt3support -qt-libpng -qt-libmng
      -qt-libtiff -qt-libjpeg -glib -platform linux-g++-64 -confirm-license -no-openssl -no-qdbus -prefix ./static_new -prefix-install -opengl -sm -L/usr/lib64 -lSM -lICE -xshape -lX11 -xinerama -lXinerama
      -xcursor -lXcursor -xfixes -lXfixes -xrandr -lXrandr -xrender -lXrender
      -fontconfig -lfontconfig -tablet -lXi -xkb -glib -lglib-2.0 -lXext -lz
      -lgthread-2.0
      5 gmake
      6 gmake install
      then I only have to put following lines in my makefile

    SLIBS += QtGui QtCore
    I do not have to put code in my makefile to link X libraries in the final executable

    My question in why do have explicitly link X libraries while integrating static libraries libQtGui.a and libQtCore.a in my final executable


  • Moderators

    @Qt-Enthusiast No, you can't link dynamic libraries to static libraries. Even if this would be possible - what would be the point? In any case your app will depend on those dynamic libraries.


  • Qt Champions 2016

    @Qt-Enthusiast said in Is it possible to link dynamic library /usr/lib64 while making static libraries of QT:

    Is it possible to link dynamic libraries like -lXi -lXfixes while making static libraries of QT

    Yes.

    @Qt-Enthusiast said in Is it possible to link dynamic library /usr/lib64 while making static libraries of QT:

    and do no link these libraries when making final execuatble

    No!

    @jsulm said in Is it possible to link dynamic library /usr/lib64 while making static libraries of QT:

    No, you can't link dynamic libraries to static libraries.

    Technically you can. Practically, however, it's not so useful, as you pointed out.



  • @kshegunov said in Is it possible to link dynamic library /usr/lib64 while making static libraries of Qt:

    Technically you can. Practically, however, it's not so useful, as you pointed out.

    Could you write the sample code how I will link the shared libraries while making static libraries of QT

    configure -release -static -largefile -qt3support -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -glib -platform linux-g++-64 -confirm-license -no-openssl -no-qdbus -prefix ./static
    -prefix-install -opengl -sm -L/usr/lib64 -lSM -lICE -xshape -lX11 -xinerama -lXinerama -xcursor -lXcursor -xfixes -lXfixes -xrandr -lXrandr -xrender -lXrender -fontconfig -lfontconfig
    -tablet -lXi -xkb -glib -lglib-2.0 -lXext -lz -lgthread-2.0



  • I don't think @kshegunov intention was to give you hope. What you are trying to do is wrong. Even if you do it you'll have duplicate symbols and you will still have to deploy the dynamic libraries. I see no point in what you are trying to do



  • I have rephrase my question
    t Enthusiast about 3 hours ago @kshegunov
    @kshegunov @jsulm

    I have changed the question , if you can let me know the answet


  • Qt Champions 2016

    @Qt-Enthusiast
    I still don't get why you want or need this. And as @VRonin correctly deduced from my demeanor, I think it's wrong on so many levels ... but for what's worth here you go:

    configure -L <External Lib Path> -l <External Lib> -I <Additional Include dir>
    


  • I need this because , I build my executable with this static library on machine linux Red Hat 5 ,8 , the Xi Xfiles so on
    are picked from /usr./lib64/

    but on other machine with same configuration linux Red Hat 5 ,8 its says
    /usr/ld cannot find -Xi .

    I dont know why


  • Qt Champions 2016

    @Qt-Enthusiast said in Is it possible to link dynamic library /usr/lib64 while making static libraries of Qt:

    but on other machine with same configuration linux Red Hat 5 ,8 its says
    /usr/ld cannot find -Xi .
    I dont know why

    Because you need to link that library to the application if it was used in a static library (that's what @jsulm was referring to, for this type of linkage is being dubious at best). The static library can be linked against dynamic libraries, but will not include, and I can't stress this enough, any symbols from those dynamic libraries. The linkage against the dynamic libraries needs to be done when the final application/shared object is created (when the ELF header is generated). So now you should know why.

    Since that's somewhat technical matter, my advice yet again is: either link everything statically or link everything dynamically, especially if you're not clear how exactly the linker/loader (co)operate.


  • Qt Champions 2016

    PS:
    Read here for how static libraries work.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.