How to use shared object with qtcreator/linux OF?

I’m trying to use an external library ( in my openframeworks project with qtcreator on ubuntu 16.04 based eOS.

In the past 3 days I’ve (unsuccessfully) tried compiling the library and including the .so object (in the .qbs and config.make), all without success though.

I can post my current setup and error messages if that helps, but it isn’t clear to me what the steps are at all (where do you even put the .so file to get it included in the build?


this is something that you do using qbs syntax… for example if you wanted to add a library called in the project qbs file below the of.* flags you can add:

cpp.dynamicLibraries: ["math"]
cpp.libraryPaths: ["libs"]

and then put the library in a libs folder in your project. Of course libraryPaths can be any folder or collection or folders, (both variables are javascript style arrays) and if the .so is a system library in /usr/lib or similar then you don’t need to add the library path

the full reference for the cpp module of the qbs filesystem can be found here: and some variable in that module are already filled in by the OF module so you need to use them as of.* instead of cpp.*

Those are specified in the default OF qbs file:

        of.pkgConfigs: []       // list of additional system pkgs to include
        of.includePaths: []     // include search paths
        of.cFlags: []           // flags passed to the c compiler
        of.cxxFlags: []         // flags passed to the c++ compiler
        of.linkerFlags: []      // flags passed to the linker
        of.defines: []          // defines are passed as -D to the compiler
                                // and can be checked with #ifdef or #if in the code
        of.frameworks: []       // osx only, additional frameworks to link with the project
1 Like

Thanks @arturo for such a quick reply! I should’ve asked here days ago haha.

After trying the cpp flags you suggested and trying to build, qtcreator tells me:

cannot find -lcpd

My .so files are in ofproject/cpd/build/ (,,

And my ofproject/project.qbs file has:

cpp.dynamicLibraries: [“cpd”]
cpp.libraryPaths: ["…/cpd/build"]

(after the of.* flags)

When I change the cpp.libraryPaths and try build, qtcreator gives me this error instead:

/home/dsk/Downloads/of_v0.9.8_linux64_release/apps/myApps/homography2/bin/homography2_debug: error while loading shared libraries: cannot open shared object file: No such file or directory

I know the cpd library I’m trying to use depends on CMake and Eigen at build time only, I installed Eigen on synaptic package manager, could the issue be related to cpd depends?


i think the correct path should be cpd/build without the … if cpd is directly in the project folder

That path gives me “ cannot open shared object file: No such file or directory”

perhaps check, it’s usually a soft link and it might have an absolute path pointing to the wrong path

Just tried renaming (the shared library itself) to and got the same error saying wasn’t found.

Like programming in general, the problem is probably really obvious but I’ve never done this before and don’t fully understand how it works, so thanks so much for your help! :smiley:

edit: and the files are pointing to eachother like this: -> ->

oh i think the problem is that is already compiling correctly but it also needs to find the library when running the binary. there’s a linker flag, rlink that sets that. in qbs it’s:

cpp.rpaths: ["cpd/build"]

but don’t remember exactly now is if that path is relative to the project, the binary or it needs to be aboslute so try which one works

1 Like

Thanks ^^ I’ll check out the qbs reference and try figure it out

I copied the cpd shared object into /usr/lib/ and am getting the same error that is missing

Why is it looking for when I’ve only told the .qbs project file to look for cpd?

you could try cleaning the project and recompiling. also dynamic libraries are complicated to setup, it’s probably easier to just recompile your library as static. if it’s a cmake library as you posted earlier there are a couple of flags to setup cmake to compile as static

1 Like

Sorry for hijacking/resurrecting someone else’s thread, but I’m facing this exact issue. I’m trying to use the ofxASR addon, and it comes with the libraries libs3decoder and libsphinxbase into the addon folder, so I tried adding:

cpp.staticLibraries: [
cpp.rpaths: [FileInfo.joinPaths(of_root, '/addons/ofxASR/libs/sphinx/lib/linux')]
cpp.libraryPaths: [
    FileInfo.joinPaths(of_root, '/addons/ofxASR/libs/sphinx/lib/linux')

But still, when I try to build it, it says that could not find both -ls3decoder and -lsphinxbase. Any ideas?

try changing the names od the libraries to .so instead of .so.1 as they arre in the original. in any case, if those libraries are in the linux forlder they are surely 32 bits and you are probably on a 64bits system so they won’t work. Those libraries are in the ubuntu (or most other distros) repos so it’s probably easier to install them in the system and you won’t need to add any rpath or library paths

Yes, probably the 32-64 bits issue was the biggest problem, couldn’t get them to work. Ended up downloading the libs and building / installing on the system. Now I’m just working on updating the addon to work with the newest version, but at least the link step went fine. Thanks @arturo!

It seems I’ve spoken too early… adding the cpp.staticLibraries block seemed to solve the linking issues, but it also broke all references to boost and other oF linked libraries, because I was overwriting what was defined on ofApp.qbs. But any other way I try to add the libs, be it on the of.pkgConfigs or even adding it directly in the ofApp.qbs gives me a “error while loading shared libraries: cannot open shared object file: No such file or directory”, even though the libraries are correctly installed on /usr/local/lib. Thoughts on it?


this seems to be a bug in the OF qbs file. for other flags we have of. versions of the cpp equivalents but not for libraries. i’m adding them in master but if you want to use it in previous versions you can probably just use theof.linkerFlags and add them as -ls3decoder or there might be a pkg-config that you can set in of.pkgConfigs

another option is to create an addon_config.make in the addon root to specify this libraries of pkg-configs that way every time you want to use that addon in a project you won’t need to reconfigure the project itself.

here’s an example:

Adding the values on of.linkerFlags gives me reference errors as if I didn’t have the libraries included at all (a bunch of undefined references to all the methods in the libs). To try to force the libraries I’m changing the ofApp.qbs file like this:

cpp.staticLibraries: of.coreStaticLibs.concat([

Then it throws the linking error: error while loading shared libraries: cannot open shared object file: No such file or directory I’ve also tried some other ways of linking the libraries, all got the same error, and I’m running out of ideas. Any other way that I may be able to link them? Pointing to local files in the project folder or something like that?

have you tried using pkg-config? that’s usually the easiest:

of.pkgConfigs: ["sphinxbase"]

It gives me the same loading errors as adding to the cpp.staticLibraries

Solved! When installing from source the libs go to /usr/local/lib, which is not default to include them. Adding the libs to of.pkgConfigs and /usr/local/lib to of.includePaths did the trick. Thanks a lot!