r0ng r0ng - 3 months ago 25x
Linux Question

Qt qbs project settings with library not found compile error

I am working on a project which has several levels. Personally, I am new to qbs and there are not many document and examples on the internal about qbs.


Qt5.6.1; Qt creator 4.01; Ubuntu 16.04; Qbs 1.5.1

Here is the hierarchy of the project. On the top level, it has project.qbs:

import qbs
import qbs.File
var binaries = [
"subpro/subpro.qbs", // <- 1. the project I am working on
"ourlib/ourlib.qbs", // <- 2. the library I am using
return binaries

The subpro.qbs is something like:

import qbs
Project {
name: subpro
"myapp/myapp.qbs" //<- 3. the application I am working on


The myapp.qbs is like:

import qbs
type: "application"
name: "myapp"
name: "project-install"
fileTagsFilter: "application"
qbs.install: false
qbs.install: "bin"
Depends {name:"cpp"}
Depends {name:"blah1"}
Depends {name:"ourlib"}

cpp.libraryPaths:["path_of_lib3rdParty"] // 4. set the 3rd party lib path
cpp.staticLibraries:["lib3rdParty.a"] // 5. set the 3rd party lib name


finally the qbs for our lib:

import qbs
name: "ourlib"
name: "project-install"
fileTagsFilter: "dynamiclibrary"
qbs.install: false
qbs.installDir: "debug"

Depends {name: "cpp"}
cpp.libraryPaths:["path_of_lib3rdParty"] // 6. same as 4
cpp.staticLibraries:["lib3rdParty.a"] // 7. same as 5

When I run "qbs debug" under the project root folder.
The qbs shows:

linking ourlib.so
compiling myapp.cpp
ERROR: ...
/usr/bin/ld: cannot find -llib3rdParty_s.a

So, based on the error message, the qbs failed to build myapp.cpp and trying to find the lib3rdParty in myapp project. I added 4 and 5, still having the same error. It seem 6 and 7 are correct since there is no linking error from ourlib.so. How should I config the qbs to make the building process working?

Another question is about the keyword "references". Can I reference other qbs file in any level in a project? How it work? I got the same question about "Depends" as well.




The cpp.dynamicLibraries and cpp.staticLibraries properties take a list of library names to be linked, i.e. the library name without the lib prefix or .so suffix.

For example, you'd use:

cpp.libraryPaths: ["/home/r0ng/tools/myapp/libs/relic/lib"]
cpp.dynamicLibraries: ["relic"]

However, since you already have the full file path of the dynamic library you wish to link, you can simply pass the full file path without having to specify cpp.libraryPaths at all, like so:

cpp.dynamicLibraries: ["/home/r0ng/tools/myapp/libs/relic/lib/librelic.so"]

That second method is preferred because it specifies the exact library to link to, rather than relying on the search path which may not necessarily pick the type of library you expect (if both a static and dynamic version exist).

I concede that our cpp.dynamicLibraries and cpp.staticLibraries properties should be better documented to explain their intended use.

Regarding references, yes, you can reference any file path regardless of its file system location.

Regarding Depends, that item's name property specifies the name of a product or module to create a dependency on. Such a product or module must already be present in your project tree, for example having been loaded as a result of using the qbsSearchPaths or references properties.