Results 1 to 3 of 3

Thread: Linking a custom shared library

  1. #1
    Join Date
    May 2011
    Qt products

    Default Re: Linking a custom shared library

    Dear all,

    I'm using QtCreator on Ubuntu x64.

    I've created a shared library MilpLibrary which I use in another application MilpClient. The library builds well, and so does the application. But when I run the application MilpClient it exits with an error:
    error while loading shared libraries: cannot open shared object file: No such file or directory
    and also ldd confirms that the linked library is not found.

    Only after running make and sudo make install on the library build dir (that installs the in /usr/lib) the application MilpClient will run.

    I would like to not need to install the in /usr/lib and still be able to use the library.

    What am I doing wrong?

    Thanks in advance!

    This is the .pro-file of MilpClient:
    Qt Code:
    1. QT += core
    2. QT += gui
    3. QT += network
    5. TARGET = MilpClient
    6. TEMPLATE = app
    7. SOURCES += main.cpp\
    8. mainwindow.cpp \
    9. ETC...
    10. HEADERS += mainwindow.h \
    11. ETC...
    13. FORMS += mainwindow.ui \
    14. ETC...
    16. # include own lib
    17. INCLUDEPATH += /home/simon/MilpLibrary # header files
    18. LIBS += -L/home/simon/MilpLibrary-build-desktop -lMilpLibrary # .so files
    To copy to clipboard, switch view to plain text mode 

    Added after 17 minutes:

    It works if I do a:
    Qt Code:
    1. export LD_LIBRARY_PATH=/home/simon/MilpLibrary-build-desktop
    To copy to clipboard, switch view to plain text mode 

    Is this the way to go?

    Added after 1 6 minutes:

    I've found no way to add this to the build environment of QtCreator.

    What permanently works, is adding a file to /etc/ with the appropriate library path and than running "sudo ldconfig -v"...

    Anyone better ideas?
    Last edited by nomiz; 4th March 2012 at 18:38.

  2. #2
    Join Date
    Apr 2010
    Russian Federation, Kaluga
    Thanked 3 Times in 3 Posts
    Qt products
    Unix/X11 Windows

    Default Re: Linking a custom shared library

    Dynamic linker (on Linux) seeks shared libraries at known to him directories. Like (/usr/lib, etc).
    If you run: ldd <you executable file> - you can see, than your so isn't found.
    So have two ways:
    1. Put your so file, or link for it to common directory.
    2. Run your program through script, where you set LD_LIBRARY_PATH before executing your program.

    P.S. Sorry for my english.

  3. #3
    Join Date
    May 2011
    Qt products

    Default Re: Linking a custom shared library

    Ok, thanks. So there's no QtCreator setting that will do this at runtime for me?

Similar Threads

  1. Replies: 10
    Last Post: 20th December 2015, 12:14
  2. Replies: 3
    Last Post: 7th February 2012, 11:40
  3. Split project into shared libs - linking issue.
    By porterneon in forum Newbie
    Replies: 9
    Last Post: 30th May 2011, 15:15
  4. Shared Object In Qt and Linking to main application
    By Ashutosh2k1 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2011, 11:36
  5. Replies: 1
    Last Post: 5th March 2007, 21:50

Tags for this Thread


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.