Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Basically there are two ways:

  • You use the qt-way by a using *.pro file and link here against OpenCV:

    OPENCV_ROOT = c:/OpenCV2.4.3

add opencv libraries and include path ( Note: here are several libs missing, add them! )

LIBS += -lcxcore$${OPENCV_SUFFIX} -L$${OPENCV_ROOT}/lib
INCLUDEPATH += $${OPENCV_ROOT}/include
  • Or you use cmake and generate a CMakeLists.txt and add the following lines:

for QT:

find_package(Qt4 REQUIRED)
if(QT_FOUND)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR})
endif(QT_FOUND)

for OpenCV:

find_package( OpenCV REQUIRED ) 
if( OpenCV_FOUND )
list( APPEND ThirdParty_LIBS ${OpenCV_LIBS} )
    include_directories( ${OpenCV_INCLUDE_DIRS} )
endif( OpenCV_FOUND )

and finally link against them:

target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${OpenCV_LIBS})

A more complete example for a CMakeLists.txt can also be found in this answer: http://answers.opencv.org/question/5786/undefined-reference-to-algorithm/

Basically there are two ways:

  • You use the qt-way by a using *.pro file and link here against OpenCV:

    OPENCV_ROOT = c:/OpenCV2.4.3

add opencv libraries and include path ( Note: here are several libs missing, add them! )

LIBS += -lcxcore$${OPENCV_SUFFIX} -L$${OPENCV_ROOT}/lib
INCLUDEPATH += $${OPENCV_ROOT}/include
  • Or you use cmake and generate a CMakeLists.txt and add the following lines:

for QT:

find_package(Qt4 REQUIRED)
if(QT_FOUND)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR})
endif(QT_FOUND)

for OpenCV:

find_package( OpenCV REQUIRED ) 
if( OpenCV_FOUND )
list( APPEND ThirdParty_LIBS ${OpenCV_LIBS} )
    include_directories( ${OpenCV_INCLUDE_DIRS} )
endif( OpenCV_FOUND )

and finally link against them:

target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${OpenCV_LIBS})

A more complete example for a CMakeLists.txt can also be found in this answer: http://answers.opencv.org/question/5786/undefined-reference-to-algorithm/


EDIT: Update

the -L says where the lib which you specify with -l is located. So that has to be set to the path where your cx*.dll is located.