PDA

View Full Version : Linking a custom shared library



nomiz
4th March 2012, 17:38
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: libMilpLibrary.so.1: 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 libMilpLibrary.so in /usr/lib) the application MilpClient will run.

I would like to not need to install the libMilpLibrary.so 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 += core
QT += gui
QT += network

TARGET = MilpClient
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
ETC...
HEADERS += mainwindow.h \
ETC...

FORMS += mainwindow.ui \
ETC...

# include own lib
INCLUDEPATH += /home/simon/MilpLibrary # header files
LIBS += -L/home/simon/MilpLibrary-build-desktop -lMilpLibrary # .so files


Added after 17 minutes:

It works if I do a:


export LD_LIBRARY_PATH=/home/simon/MilpLibrary-build-desktop


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/ld.so.conf.d/ with the appropriate library path and than running "sudo ldconfig -v"...

Anyone better ideas?

grin
5th March 2012, 05:20
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.

nomiz
5th March 2012, 06:48
Ok, thanks. So there's no QtCreator setting that will do this at runtime for me?