Results 1 to 13 of 13

Thread: Adding a shared library to a qt application

  1. #1
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Adding a shared library to a qt application

    Hi,
    I am trying to add an external library to a qt application. But after building the application its showing cannot recognize file format. Library is in .so format and I am working on linux. Please help.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Not sure I follow.
    But after building the application
    It sound like you can build the application.
    If this is true, then your lib is linked as it should, otherwise the linker would complain.

    I guess what is not so clear is what do you mean with "adding" the lib.
    More information would help.

    It sound more like your are trying the open an *.so file with your application.
    Is that the case?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Currently the application has some cpp files which are included in the pro file. (It will give a successful build)
    Instead what I am trying to do is to add those cpp files as a shared library.(On trying to build will show file format not recognised build failed)


    Added after 1 43 minutes:


    Please help me on how to add the cpp files as a shared library to a qt application.
    Last edited by bravestar; 27th April 2017 at 07:25.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Ok, what you want is to build a shared lib.
    You should do it in a separate project, either a completely separate project, or a sub-project of the one you have now.
    If you are using QtCreator simply do: File->New File or project
    Then select "Library" from the possible options on the left, and and C++ library on the right side.
    Also have a look at this:
    https://wiki.qt.io/How_to_create_a_l...an_application
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Thanks that really helped!
    Is there anyway to know which all shared libraries are linked to an application in qt?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    If you have the source code, and this is a qmake project (using *.pro files) you can look for the 'LIBS' variables in your *.pro/*.pri files.
    Uder linux you can use the ldd command on the executable : http://man7.org/linux/man-pages/man1/ldd.1.html
    For windows, you can use dependency walker: http://www.dependencywalker.com/
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Thanks
    Now the shared library has been made.
    I am making the shared library for a qt application which has to run on a target board. How will I link the shared library to the executable as it is running on a board.

  8. #8
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Please help

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding a shared library to a qt application

    If your executable is running on a board, then you have built it using a cross-compiler tool chain for that board, right? Your shared library has to be built with the same cross-compiler tool chain and symbolically linked into the executable (that is, the executable has been told that there are functions it will be calling that can be found in a shared library of a certain name).

    You now need to install the shared library into the board's OS. Most of the time this is done by copying the file into a known location in the file system used by the board - the same folder as the executable or a known location for shared libraries.

    If you are directly downloading the executable into the board's memory (like with an Arduino sketch), then you're going to have to consult the Arduino manuals for how to add this.

    The question is, if you are running this on an embedded board, why do you need a shared library in the first place?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    @bravestar
    What OS is running on your board?
    If it is some sort of linux, you can put your shared lib in a path of your choice, and add that path to LD_LIBRARY_PATH. (in addition to putting it next to the application executable as d_stranz said)
    The linker will look the path for the libs from that system variable.
    Note: if your shared lib is doing write operations, or other operations that need elevated rights, and the application you are running is a user space application, make sure the location of your shared lib is not a location needing elevated rights.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. The following user says thank you to high_flyer for this useful post:

    bravestar (16th May 2017)

  12. #11
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Thanks a lot.
    I have added the LD_LIBRARY PATH, and tried to run the application. Its not working. Do I have to use subdirs for handling dependencies.


    Added after 8 minutes:


    @high_flyer OS is linux
    Last edited by bravestar; 11th May 2017 at 07:38.

  13. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    show the ldd output on your executable
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  14. #13
    Join Date
    Apr 2017
    Posts
    7
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding a shared library to a qt application

    Thank you very much guys. I tried making libraries using cmake and it worked!

Similar Threads

  1. Depoyment Qt application as Shared Library
    By norrbotten68 in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2014, 00:13
  2. Using symbols from loading application in shared library
    By barteksch in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2010, 17:08
  3. How to deploy application using shared library in Linux
    By cutie.monkey in forum Installation and Deployment
    Replies: 9
    Last Post: 21st January 2010, 18:41
  4. Application with shared library problem in linux
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2010, 07:20
  5. qmake: dependency of application on common shared library
    By PeterWurmsdobler in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2009, 16:13

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.