3
votes


We have a problem building out C++ software on Ubuntu Linux with qmake.
Problem is: we use some library, for example OpenCV, that can have different versions in one system.
qmake automatically add -L/usr/lib or -L/usr/lib/x86_64-linux-gnu to g++ arguments, and contents of LIBS variables after it.
So there conflicts with different versions of OpenCV, the system version is used, but we need custom one, located at our build tree. Are there any methods to change libs order in -L or something else to solve this problem?

3
have you solved this problem?Elvis Dukaj
you could explicitly specify a path: LIBS += -l${OPENCV_HOME}/lib/opencv_coreedwinc

3 Answers

1
votes

There are two components to doing this:

First, you need to make sure to include them in your .pro file correctly. Do this with something like (this is from my current project):

LIBS +=      L${OPENCV_HOME}/lib \
            -lopencv_core \
            -lopencv_highgui \

You can replace the environment variable with whatever your path is. I've found it convenient to use environment variables like this because you also need header includes:

INCLUDEPATH += $$(OPENCV_HOME)/include/opencv2 \
               $$(OPENCV_HOME)/include/opencv \
               $$(OPENCV_HOME)/include

This allows you to create projects and build them correctly.

When you attempt to run them, however, you will likely run into all sorts of issues due to your app finding the wrong libraries (from system libraries like you say) - you need to set your LD_LIBRARY_PATH variable correctly. In this case I have a launch script (you can do this in your user profile or elsewhere) which contains:

export LD_LIBRARY_PATH=${OPENCV_HOME}/lib

Which then looks to that (as well as other) locations on the LD_LIBRARY_PATH first, before system libraries.

0
votes

Another hack is to exploit the LIBS = $(SUBLIBS) ... part of the Makefile qmake writes. Namely, invoke the generated Makefile with

make SUBLIBS=-L/path/to/your/opencv
0
votes

I had the same issue which I fixed by setting QMAKE_LIBDIR to the lib directory of the build tree. QMake automatically added the system library path after this value, thus allowing to correctly detect the desired libraries:

QMAKE_LIBDIR = /path/to/desired/opencvlib