# order of -lopencv_core -lopencv_highgui -lopencv_photo -lopencv_videoio -lopencv_imgproc -lopencv_calib3

-llibrary -l library

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

The shared libraries, for example libopencv-video, require other libraries and themselves are required by other libraries.

Does this mean that in the compile command their order ( -lopencv_core -lopencv_highgui -lopencv_photo -lopencv_videoio -lopencv_imgproc -lopencv_calib3) matters?

edit retag close merge delete

Sort by » oldest newest most voted

as long as you're linking dynamic libs, the order does not matter at all.

quite a different picture with static libs, since you have to sort them by dependancy. you also need to explicitly link to all dependancies (like e.g. zlib) which were conveniently linked to the so's when building the libs.

so, if you have :

-lopencv_core -lopencv_imgcodecs -lz -lpng


core has to go after imgcodecs, which depends on png, which depends on zlib, so it must be:

-lopencv_imgcodecs -lopencv_core -lpng  -lz

more

Thank you.
This syntax does not allow .so or .a extentions. Does it mean that static and dynamic libs should not be in the same folder not to confuse the linker?

Also I read somewhere that lopencv_core is a root in sense that all other libs depend on it and therefore it should go first. Now I see I am wrong. Where can see the interconnections between the main OpenCV libs (-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_photo -lopencv_videoio -lopencv_video -lopencv_imgproc -lopencv_calib3d)? I.e. which depends on which?

( 2020-04-28 11:36:34 -0500 )edit

Official site

GitHub

Wiki

Documentation