[QBS] Internal libraries, RPATH and Qt Creator

Christian Gagneraud chgans at gna.org
Thu Apr 30 06:03:24 CEST 2015

On 30/04/15 14:48, Jake Petroules wrote:
> Hi Christian,
> Generally when using rpath you'll want to set it to @loader_path/../lib
> or @loader_path/../Frameworks on OS X, and $ORIGIN/../lib on Linux. If
> you install your binaries and libraries in a standard structure like:
> *- «install-root»/*
> *-- bin/*
> *---- myapp*
> *-- lib/*
> *---- libfoo.so*

Hi Jake,

Thanks for the explanation, I think I now understand better, my problem 
is that I installed libs in a subdir of lib, like lib/myproject. So I 
guess I just have to adjust the rpath things: ../lib => ../lib/myproject.

I think I got confused by how Qtc is doing it:

     cpp.rpaths: qbs.targetOS.contains("osx")
             ? ["@loader_path/..", "@executable_path/.."]
             : ["$ORIGIN", "$ORIGIN/.."]

     cpp.installNamePrefix: "@rpath/PlugIns/"
     cpp.rpaths: qbs.targetOS.contains("osx")
         ? ["@loader_path/..", "@loader_path/", "@executable_path/.."]
         : ["$ORIGIN", "$ORIGIN/.."]

     property string libDirName: "lib"
     property string ide_library_path: {
         if (qbs.targetOS.contains("osx"))
             return ide_app_target + ".app/Contents/Frameworks"
         else if (qbs.targetOS.contains("windows"))
             return ide_app_path
             return libDirName + "/qtcreator"
     property string ide_plugin_path: {
         if (qbs.targetOS.contains("osx"))
             return ide_app_target + ".app/Contents/PlugIns"
         else if (qbs.targetOS.contains("windows"))
             return libDirName + "/qtcreator/plugins"
             return ide_library_path + "/plugins"

My first attempt was to simply copy/paste their stuff, but it seems to 
me that it cannot work since libs are installed in lib/qtcreator, but 
rpath is set to ../lib instead of ../lib/qtcreator.
Or maybe I'm missing something else...

I think I will instead install the libraries in lib/ and make sure they 
are named using a prefix of mine (eg. libProjFoo.so), and install the 
plugins the "Qt" way (eg. $$[QT_INSTALL_PLUGINS]/myproject).

> Then everything should "just work" with `qbs run`. There's even some
> environment variable magic baked into the cpp module on OS X (and Linux,
> I think?) so that your applications will run using `qbs run` even if you
> don't set an rpath.

I have just tried, and without manipulating the rpath in my qbs files, 
"qbs run" will return me a link error, weird...

> You mentioned wanting to do this "without installing files" but Qbs has
> a feature that "installs" your outputs into a subdirectory of your build
> directory, a process which happens by default. I'm assuming that by

Yes, I saw that, I think it's a neat feature

> "install" you meant at the system level, which is of course not


> necessary to be able to use `qbs run`. Here's a small sample project
> demonstrating Qbs installation and the proper use of rpaths:
> Just cd to the directory and type `qbs run` -- that's all.

Hum, interesting qbs file, thanks a lot for sharing!

/me going for more QBS hacking...

Thanks a lot!

PS: a bit off-topic here, but I was looking for a QVersion 
implementation this afternoon, and I found one of yours! [1] ;)
Didn't the Qt project at some point plan to have this mainstream? I 
remember some discussion on Qt dev or interest, but couldn't find it back.


>> On Apr 29, 2015, at 5:48 PM, Christian Gagneraud <chgans at gna.org
>> <mailto:chgans at gna.org>> wrote:
>> Hi there,
>> I recently decided that it was time for me to give a go at using Qbs
>> (I've been using Qtc w/ qmake from day 1). My project has a typical
>> layout/structure:
>> .
>> ├── doc
>> ├── share
>> ├── src
>> │   ├── app
>> │   ├── libs
>> │   └── plugins
>> └── tests
>> As I didn't really know how to get started, I decided to have a look at
>> Qtc's own Qbs code, and to my surprise, it's quite simple and straight
>> forward.
>> So I ended up writing 4 custom items:
>> - LedaProduct (common base item)
>> - LedaApplication
>> - LedaLibrary
>> - LedaPlugin
>> I'm not using the plugin stuff yet (I haven't written the loader), so
>> for now my plugins are based on LedaLibrary, and the app includes the
>> plugins header, link against the fake plugins and do all the setup
>> "manually".
>> Anyway, all build fine, but I'm having problems resolving the library
>> loader path at runtime (using qtcreator).
>> I have tried to use "cpp.rpaths: [project.buildDirectory + "/" +
>> project.leda_library_path]" in LedaApplication, but it screws up the
>> linking of my app (there's a -l/fullpath/.socopy/libfoo.so that appears
>> on the command line).
>> So my question is how do I set up my Qbs files so that I can run my app
>> (without installing files) using the Qt Creator "run" command? (note: of
>> course I still want too to be able to do a local or system install and
>> run the app from there)
>> My question concerns both app/libs dependencies but as well lib/lib and
>> plugin/lib ones too.
>> It would be nice if someone could shed some light on this, or point me
>> to an example or documentation.
>> Thanks, and long live qbs!
>> Krys
>> _______________________________________________
>> QBS mailing list
>> QBS at qt-project.org <mailto:QBS at qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/qbs
> --
> Jake Petroules - jake.petroules at petroules.com <http://petroules.com>

More information about the Qbs mailing list