Adding Required Includes and Libs for OpenCV 3.4.1 in qmake Projects

Here is what you need to add to your Qt qmake projects to be able to add and use OpenCV 3.4.1 default set of libraries. I usually add them into a separate *.pri file and include that in my *.pro files to avoid repetition, but that’s up to you. Well, here it is:

INCLUDEPATH += "opencv_3.4.1_include_path"

debug: {
	LIBS += -L"opencv_3.4.1_lib_path" \
		-lopencv_calib3d341d \
		-lopencv_core341d \
		-lopencv_dnn341d \
		-lopencv_features2d341d \
		-lopencv_flann341d \
		-lopencv_highgui341d \
		-lopencv_imgcodecs341d \
		-lopencv_imgproc341d \
		-lopencv_ml341d \
		-lopencv_objdetect341d \
		-lopencv_photo341d \
		-lopencv_shape341d \
		-lopencv_stitching341d \
		-lopencv_superres341d \
		-lopencv_video341d \
		-lopencv_videoio341d \

release: {
	LIBS += -L"opencv_3.4.1_lib_path" \
		-lopencv_calib3d341 \
		-lopencv_core341 \
		-lopencv_dnn341 \
		-lopencv_features2d341 \
		-lopencv_flann341 \
		-lopencv_highgui341 \
		-lopencv_imgcodecs341 \
		-lopencv_imgproc341 \
		-lopencv_ml341 \
		-lopencv_objdetect341 \
		-lopencv_photo341 \
		-lopencv_shape341 \
		-lopencv_stitching341 \
		-lopencv_superres341 \
		-lopencv_video341 \
		-lopencv_videoio341 \

Note that this is relevant only to Windows OS and you need to replace “opencv_3.4.1_include_path” and “opencv_3.4.1_lib_path” with the correct paths on your computer. Provided that you build OpenCV by turning on the opencv_world flag during the build process, then you only need to include that single lib instead of all of the libraries mentioned above. Here’s how:

INCLUDEPATH += "opencv_3.4.1_include_path"

debug: {
	LIBS += -L"opencv_3.4.1_lib_path" \

release: {
	LIBS += -L"opencv_3.4.1_lib_path" \

On Linux though, you can use PKGCONFIG to include the libs quite easily, as seen here:

CONFIG += link_pkgconfig
PKGCONFIG += opencv

And on macOS you can use the following:

INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/ lib \

Note that you can also add operating system flags to a qmake *.pro file and make you project configurations cross-platform. Here’s what you need to do:

win32: {

unix: !macx {

unix: macx {

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.