1

I'm using opencv in my qt project, and I want to link it. But th qbs for my project does not find my opencv module. Here is my file structure:

MyProject/
├── build/
├── opencv/
│ ├── debug/
│ │ └── include/, lib/
│ ├── release/
│ │ └── include/, lib/
│ └── opencv.qbs
├── src/
│ └── main.cpp
└── MyProject.qbs <-- Main project file

Here is my opencv.qbs file :

import qbs.FileInfo
Module {
 name: "opencv"
 Export {
 Depends { name: "cpp" }
 cpp.includePaths: qbs.buildVariant == "release" ? "release/include" : "debug/include"
 cpp.libraryPaths: qbs.buildVariant == "release" ? "release/lib" : "debug/lib"
 cpp.dynamicLibraries: qbs.buildVariant == "release" ? [...files...] : [...filesd...]
 }
}

And here is MyProject.qbs:

import qbs.FileInfo
QtApplication {
 Depends { name: "Qt.widgets" }
 Depends { name: "opencv" }
 cpp.defines: [
 // You can make your code fail to compile if it uses deprecated APIs.
 // In order to do so, uncomment the following line.
 //"QT_DISABLE_DEPRECATED_BEFORE=0x060000" // disables all the APIs deprecated before Qt 6.0.0
 ]
 files: [
 "src/**",
 ]
 references: [ "opencv/opencv.qbs" ]
 install: true
 installDir: qbs.targetOS.contains("qnx") ? FileInfo.joinPaths("/tmp", name, "bin") : base
}

the line Depends { name: "opencv" } is flagged Dependency 'opencv' not found for product 'deconv'.

asked May 19, 2025 at 13:54

2 Answers 2

1

The two problems here are:

  • You do not pull in modules via "references" like products; instead, they are looked up via the module search paths; see https://doc.qt.io/qbs/custom-modules.html.

  • Modules cannot contain Export items. All the property bindings in a module are "exported" automatically to the depending product.

  • You don't set a module's name explicitly; it is derived from the location (see above).

In fact, referencing a module item this way triggers an error:

ERROR: Item type should be 'Product' or 'Project', but is 'Module'.

So I suspect your actual project doesn't quite look like what you pasted here.

Note that alternatively, you can use your layout as is by changing the Module to a Product (the Export item also creates a module).

answered May 19, 2025 at 14:47
Sign up to request clarification or add additional context in comments.

2 Comments

My project is exactly as presented, however after reviewing your answer and tweaking with another clean project (which wasn't that different, it simply didn't have as many lib/include/bin files) I had to do the following : Change Module to Product, and in the top-level .qbs, pack QtApplication in the scope of Project and pull the "references" property above (and out of) QtApplication. Honestly QtCreator compile errors could be a LOT more explanatory. But thank you for your comment
Oops, I overlooked that the "references" was on the product level. I'll see whether we can throw an error for that.
0

As it turns out, and it's not made clearly in the documentation, if you want to link or add an external library, you should pack the importing application into a Project and reference your library from that Project and not from the application:

Project {
 references: [ "opencv/opencv.qbs" ] // OK
 QtApplication {
 Depends { name: "opencv" }
 // references: [ "opencv/opencv.qbs" ] // WRONG
 }
}

If you want to import external resources, these should be placed in a Product with the exported include/binaries/lib files:

Product {
 name: "opencv"
 Export {
 Depends { name: "cpp" }
 cpp.includePaths: ...
 cpp.libraryPaths: ...
 cpp.dynamicLibraries: ...
 }
}

Or from my understanding, use a Module only if it is globally shared (e.g needs to be in your %appdata% folder in Windows) or locally, see Christian Kandeler's answer for more information.

answered May 19, 2025 at 15:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.