Andrew February 2016

Setting PATH/LD_LIBRARY_PATH for 'make check' with QMake

I have a project setup with a couple of Apps with a shared library, this is all built nicely using a SUBDIRS project, where the apps depend on the shared library.

TEMPLATE = subdirs
SUBDIRS = app1 app2 sharedLib
app1.depends = sharedLib
app2.depends = sharedLib

Each app also contains a number of tests, with CONFIG += testcase set.

This creates a check target so we can run all unit test from the top level .pro using make check.

The problem is that some of the app tests require the presence of the code within the sharedLib, therefore it needs to be discoverable according to each platforms library lookup rules.

On Windows one option is to have the sharedLib location on the PATH, on linux we can add the sharedLib location to LD_LIBRARY_PATH, on mac DYLD_LIBRARY_PATH.

One solution is to just set the location of the built shared lib before running make check:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:build/sharedDll/
make check

and this works, but it seems a little redundant as it is the build scripts themselves that are building the shared library so they know the path to the sharedLib binary location, which can be referenced from within .pro/pri files at:

$$TOP_BUILDDIR/sharedLib/release

So, is there anyway to set the PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH from within the project files for the purposes of the make check command?

Answers


mustafagonul March 2016

If you are using gcc, you can use rpath parameter of gcc.

-rpath=dir
      Add a directory to the runtime library search path. This is used
      when linking an ELF executable with shared objects. All -rpath
      arguments are concatenated and passed to the runtime linker, which
      uses them to locate shared objects at runtime.

QMAKE_CXXFLAGS += -rpath=/the/absolute/path

If you use that technique, it will not be necessary to edit LD_LIBRARY_PATH

Post Status

Asked in February 2016
Viewed 2,969 times
Voted 9
Answered 1 times

Search




Leave an answer