PDA

View Full Version : Link to a specific version of shared library



P51D
8th June 2016, 21:52
Hi all

I've some troubles with Qt Creator and library usage: In a program I need to include a uhd libary with version 3.9.1.
I can create a static library (.a) or shared one (.so or .so.003.009 or .so.003) with the external build system.

my really strange phenomenon is, that if I run the app from Qt Creator (debug or release), the correct library is loaded (version 3.9.1). But if I run the exact same file (in the created debug/release directory) from the terminal, the used library version is 3.10 (additional installed from gnu-radio). But I have really to need version 3.9.1 to communicate with an external hardware module.
So how could I include the library correctly, that always version 3.9.1 is used?

My current .pro file looks like this:


QT += core
QT -= gui
TARGET = USRP_GUI
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app

SOURCES += main.cpp \
usrp_sdr.cpp

HEADERS += \
usrp_sdr.h

# Include all Boost and UHD (v3.9.1) header files
INCLUDEPATH += $$PWD/uhd/host/include/uhd
INCLUDEPATH += /usr/include

# Include project files
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

# Add boost header files and libraries
INCLUDEPATH += /usr/local/include/boost
LIBS += -L/usr/local/lib/ \
-lboost_system \
-lboost_filesystem \
-lboost_serialization \
-lboost_thread \
-lboost_date_time \
-lboost_regex \
-lboost_program_options

unix:!macx: LIBS += -L$$PWD/uhd/host/build/lib/ -luhd

INCLUDEPATH += $$PWD/uhd/host/build/include
DEPENDPATH += $$PWD/uhd/host/build/include

In a earlier version I hat also uhd 3.5.5 installed (from e linux distribution package). There were 3 different library versions installed without any problems and without uninstalling the older ones!? (linux is sometimes confusing)

Does anyone have a solution or suggestion?
Best regards
P51D

anda_skoa
9th June 2016, 07:02
For the runtime linker a library with the same major version is considered compatible and it uses the first one it finds.
Of course there are bad libraries out there which do not keep compatibility as they should, so a very specific version is needed.

If you have your version in your program directory, just set LD_LIBRARY_PATH in your start script to have that directory first, which will get it found before any system wide version.

You can easily test that by setting the variable in a shell and using "ldd" on your executable.

Cheers,
_