Link to tbb library required - how do I find all lib dependencies?


opencv 4.5.5
gcc 11.2
linux (latest)

is it normal to have to link with tbb library when compiling a C++ program which uses:

#include <chrono>
#include <opencv2/opencv.hpp>
#include <opencv2/wechat_qrcode.hpp>

I assume it is if I have not asked for a static library (I didn’t).
Edit: Yes I have compiled opencv with TBB option.

But this creates a small problem in deciding what libraries to add in a Makefile aimed for distributing this code to various systems with or without tbb. Shouldn’t perhaps be an entry to pkgconfig/opencv.pc so that the distributor just enquires said file on the various systems to have his code distributed?

Right now, my opencv.pc contains:

Libs: -L${exec_prefix}/lib64 -lopencv_world
Libs.private: -lm -lpthread -lcudart_static -ldl -lrt -lnppc -lnppial -lnppicc -lnppicom -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcufft -L-L/usr/local/cuda -llib64 -L-L

Shouldn’t perhaps the key “Libs” in said file contain all additional library dependencies up to -ltbb?

I am not sure what usual practice is. In my system some pc files contain -lpthread for example.

Of course there’s the key Libs.private which contains -lm -lpthread etc. So perhaps -ltbb should have been added there if indeed opencv compilation was with TBB.


It’s the OpenCV library which depends on TBB, your executable doesn’t need to link to it. So if you don’t use TBB explicitly in your code, you don’t need to add TBB dependencies to your Makefile/CMakeLists/etc.
However if you redistribute the OpenCV with your code, you have to include the libraries OpenCV was linked to.

please confirm, that you built statically linked opencv libs

because in this case, your app has to be linked against each and every dependancy lib

@kbarni, @berak
thank you for your reply,

To clarify:

This is a dynamically linked opencv.
I have :

and also
parallel_status=TBB (ver 2020.2 interface 11102)

Compiling below basic code fails:

// g++ -I /usr/local/include/opencv4/include/ test.cpp -lopencv_world
#include <chrono>
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>

int main(void){ return 0; }

Unless I also add “-ltbb” at the end of the compile command.

Have I done something wrong in the compilation of OpenCV?

well again, if you did build dynamic opencv lib(s), you only need to link against those (or -lopencv_world here)

if you have static opencv libs, you need to link your own prog against all dependancies, including tbb (also link order matters)

where do you have this ? it is not valid when building the libs

maybe show, how you built that opencv_world lib ? (cmake input/output)

and, ps, try to avoid pkg-config, it’s not well supported from the devs. rather build your own cmdline, or use cmake to generate one

Sorry, I was using the entry in CMakeVars.txt in the build dir.

I have just found out that by specifying :

export LD_LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/local/lib:/usr/local/lib64

solved the problem. (dirs there contain libtbb and libopencv_*)

Regarding pkg-config: one of its roles is to tell me what libraries to
use, library paths, include paths etc. when compiling code I distribute
to other computers which have an OpenCV not necessarily configured as
mine. I don’t know how to use cmake to enquire these settings. And
frankly I try to keep as far away from cmake as possible, though that’s
personal taste.

So, what’s the best way to enquire these settings with cmake in a
foreign system?