Results 1 to 11 of 11

Thread: Running Application linking with shared libraries in Qt/Linux

  1. #1
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Running Application linking with shared libraries in Qt/Linux

    Hi .........

    I have created a Qt application which uses some some shared libraries for running the executable.i am using Qt 4.4.0 on Windows XP.Now i want to port the same application on linux.

    i am able to run a simple Qt app on linux using qmake -pro,den qmake and make..

    i created the shared library(.so file) on linux using command
    "gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o" .

    Now i want to link this library to an executable.Could you plz tel me how can i achieve it?i am getting undefined reference errors for Qt classes i have used while trying to link the library using gcc command.

    Is there any way to accomplish these using qmake command.I am not using any IDE.

    Plz provide some solution.


    Thanks in advance......................

    Regards,
    Payal

  2. #2
    Join Date
    Sep 2008
    Posts
    58
    Thanks
    11
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Running Application linking with shared libraries in Qt/Linux

    why not using qt creator ?

  3. #3
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    k....i wil download it....

    How it wil help in linking the shared libraries?could u plz explain on that?

  4. #4
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Running Application linking with shared libraries in Qt/Linux

    Read the following page http://www.yolinux.com/TUTORIALS/Lib...ndDynamic.html
    This a very good tutorial about libraries on linux.

    Note the following points that could go wrong:
    • Remember the -L option for the path to the library and the -l option for the lib itself while linking (of course you can also specify the complete path to the lib)
    • If you can create the binary, then it should be able to find the shared lib again. You can check this with the ldd command (very usefull!!). Just run "ldd <binary>".
    • If your binary can't find the library, you need to solve this with one of the 3 options mentioned on the page above under "Library Path"


    Good luck!!

    Joost

  5. #5
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    Thanks alot..In that tutorial its mentioned how to link shared library with executable using command.......but the problem is i cant compile .cpp files developed in Qt using gcc/g++.

  6. #6
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Running Application linking with shared libraries in Qt/Linux

    In linux you use g++. Check the Makefile you created with qmake (variable CXX). In the Makefile there is also a LIBS variable which contains the libs it should use while linking. I noticed there that there is a SUBLIBS variable which is not set. I presume that if you simply do this on your command prompt:
    export SUBLIBS='-L</path/to/your/shared/lib> -l<libname>'
    And then you run make and you will be fine (I think).

    Joost

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    Your way seems to be overcomplicated... Is your shared library written in Qt? If so then in .pro file just set TEMPLATE=lib, run qmake and make without any "gcc -shared bla bla bla"
    Did you ever try to look into pro file and check it's functionalities? Doing qmake -project is fine but only for creating basic .pro file - the base for your customization - it let you avoid boring typing to add all source files to SOURCES and headers to HEADERS but not more. And linking to any library is rather easy. In your application .pro file you add:
    Qt Code:
    1. LIBS += -Lpath/to/your/library -lyourlibraryname
    To copy to clipboard, switch view to plain text mode 
    yourlibraryname is a filename without leading "lib" and trailing ".so*" so to link with "libmysql.so.4" you add "-lmysql". But then when you run your app your library has to be somewhere where OS can find it to link it dynamically so put it in your apps dir or in some dir listed in /etc/ld.so.conf or just add your library dir to /etc/ld.so.conf.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. The following user says thank you to faldzip for this useful post:

    Cupidvogel (19th December 2015)

  9. #8
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    Thanks alot, ur post is very helpful..........Now I am able to link the library.....

    I have Done the steps whatever was mentioned in the last post..............have added the LIBS in the application .pro file and edited ld.so.conf and executed ldconfig command................

    But when i am trying to run application,i am getting error like " error while loading shared libraries :libctest.so :cannot open shared object file :no such file or directory ....Dont have any idea ,how to solve the error? Could u plz help me in this regard?

    Regards,
    Payal

  10. #9
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    yaa..........the error is solved by setting the LD_LIBRARY_PATH.

  11. #10
    Join Date
    May 2014
    Posts
    136
    Thanks
    72
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    Quote Originally Posted by payal View Post
    yaa..........the error is solved by setting the LD_LIBRARY_PATH.
    How to set the LD_LIBRARY_PATH variable through Qt?

  12. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Running Application linking with shared libraries in Qt/Linux

    Quote Originally Posted by Cupidvogel View Post
    How to set the LD_LIBRARY_PATH variable through Qt?
    Since setting that variable would not have any effect on the application itself, I assume you are writing some for form of launcher application that runs programs via QProcess and needs to set their environment.

    For that QProcess has QProcess::setProcessEnvironment().

    Cheers,
    _

Similar Threads

  1. How to deploy application using shared library in Linux
    By cutie.monkey in forum Installation and Deployment
    Replies: 9
    Last Post: 21st January 2010, 19:41
  2. Application with shared library problem in linux
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2010, 08:20
  3. running application in linux
    By aj2903 in forum Qt Programming
    Replies: 5
    Last Post: 28th October 2009, 07:43
  4. Running an application with root privileges at Linux
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2009, 13:35
  5. exception in shared libraries
    By big4mil in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2006, 20:51

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.