Tuesday 19 November 2019

openCV Troubleshooting (1) : undefined reference to `cv::xxxx`


I am compiling openCV project with cmake and I am getting errors like:

test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)'
test.cpp:(.text+0x11f): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
test.cpp:(.text+0x138): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test.cpp:(.text+0x158): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
test.cpp:(.text+0x180): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'

The following compiling script won't cause the issue.
g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`

But to fix cmake compile, we need to add the following red line to CMakeList.txt.

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )


ref:

No comments:

Post a Comment