Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

undefined reference to `cv::imread

Hi, I'm using CLion as IDE and trying to link OpenCV. But I'm having problem even with a very simple app.

I prepared OpenCV binaries with these steps.

  1. Extract OpenCV files (from official website)

  2. Generate a build folder with CMake

  3. In the directory generated by CMake, execute "mingw32-make" command

  4. Add "OPENCV_DIR" to system variables. ("C:\OpenCV\mingw-build" in my case)

  5. Add "%OPENCV_DIR%\bin" to system path

My CPP Code:

image description

My CMakeLists.txt

image description

And when I try to build, I'm getting the following messages.

image description

undefined reference to `cv::imread

Hi, I'm using CLion as IDE and trying to link OpenCV. But I'm having problem even with a very simple app.

I prepared OpenCV binaries with these steps.

  1. Extract OpenCV files (from official website)

  2. Generate a build folder with CMake

  3. In the directory generated by CMake, execute "mingw32-make" command

  4. Add "OPENCV_DIR" to system variables. ("C:\OpenCV\mingw-build" in my case)

  5. Add "%OPENCV_DIR%\bin" to system path

My CPP Code:

image description

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;

int main() {
string file = "image.jpg";
Mat img = imread(file.c_str(), 1);
namedWindow("image", WINDOW_AUTOSIZE);
imshow("image", img);
waitKey(0);
return 0;
}

My CMakeLists.txt

image description

cmake_minimum_required(VERSION 3.6)
project(OpenCVFirstDemo)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(OpenCV REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(OpenCVFirstDemo ${SOURCE_FILES})

target_link_libraries(OpenCVFirstDemo ${OpenCV_LIBS})

And when I try to build, I'm getting the following messages.

image description

"C:\Program Files (x86)\JetBrains\CLion 2016.2.3\bin\cmake\bin\cmake.exe" --build C:\Users\CagdasX.CLion2016.2\system\cmake\generated\OpenCVFirstDemo-f9ecc709\f9ecc709\Debug --target OpenCVFirstDemo -- -j 8 Scanning dependencies of target OpenCVFirstDemo [ 50%] Building CXX object CMakeFiles/OpenCVFirstDemo.dir/main.cpp.obj [100%] Linking CXX executable OpenCVFirstDemo.exe CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function main': C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:9: undefined reference tocv::imread(cv::String const&, int)' C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:10: undefined reference to cv::namedWindow(cv::String const&, int)' C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:11: undefined reference tocv::imshow(cv::String const&, cv::_InputArray const&)' C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:12: undefined reference to cv::waitKey(int)' CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv6StringC1EPKc': C:/OpenCV/sources/modules/core/include/opencv2/core/cvstd.hpp:625: undefined reference to cv::String::allocate(unsigned int)' CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv6StringD1Ev': C:/OpenCV/sources/modules/core/include/opencv2/core/cvstd.hpp:667: undefined reference to cv::String::deallocate()' CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv3MatD1Ev': C:/OpenCV/sources/modules/core/include/opencv2/core/mat.inl.hpp:571: undefined reference to cv::fastFree(void*)' CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv3Mat7releaseEv': C:/OpenCV/sources/modules/core/include/opencv2/core/mat.inl.hpp:682: undefined reference to `cv::Mat::deallocate()' collect2.exe: error: ld returned 1 exit status CMakeFiles\OpenCVFirstDemo.dir\build.make:112: recipe for target 'OpenCVFirstDemo.exe' failed CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/OpenCVFirstDemo.dir/all' failed mingw32-make.exe[3]: * [OpenCVFirstDemo.exe] Error 1 CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/OpenCVFirstDemo.dir/rule' failed mingw32-make.exe[2]: [CMakeFiles/OpenCVFirstDemo.dir/all] Error 2 mingw32-make.exe[1]: [CMakeFiles/OpenCVFirstDemo.dir/rule] Error 2 Makefile:117: recipe for target 'OpenCVFirstDemo' failed mingw32-make.exe: * [OpenCVFirstDemo] Error 2

click to hide/show revision 3
No.3 Revision

updated 2016-11-18 14:13:47 -0600

berak gravatar image

undefined reference to `cv::imread

Hi, I'm using CLion as IDE and trying to link OpenCV. But I'm having problem even with a very simple app.

I prepared OpenCV binaries with these steps.

  1. Extract OpenCV files (from official website)

  2. Generate a build folder with CMake

  3. In the directory generated by CMake, execute "mingw32-make" command

  4. Add "OPENCV_DIR" to system variables. ("C:\OpenCV\mingw-build" in my case)

  5. Add "%OPENCV_DIR%\bin" to system path

My CPP Code:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;

int main() {
string file = "image.jpg";
Mat img = imread(file.c_str(), 1);
namedWindow("image", WINDOW_AUTOSIZE);
imshow("image", img);
waitKey(0);
return 0;
}

My CMakeLists.txt

cmake_minimum_required(VERSION 3.6)
project(OpenCVFirstDemo)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(OpenCV REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(OpenCVFirstDemo ${SOURCE_FILES})

target_link_libraries(OpenCVFirstDemo ${OpenCV_LIBS})

And when I try to build, I'm getting the following messages.

"C:\Program Files (x86)\JetBrains\CLion 2016.2.3\bin\cmake\bin\cmake.exe" --build C:\Users\CagdasX.CLion2016.2\system\cmake\generated\OpenCVFirstDemo-f9ecc709\f9ecc709\Debug C:\Users\CagdasX\.CLion2016.2\system\cmake\generated\OpenCVFirstDemo-f9ecc709\f9ecc709\Debug --target OpenCVFirstDemo -- -j 8
 Scanning dependencies of target OpenCVFirstDemo
 [ 50%] Building CXX object CMakeFiles/OpenCVFirstDemo.dir/main.cpp.obj
 [100%] Linking CXX executable OpenCVFirstDemo.exe
 CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function main':
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:9: undefined reference tocv::imread(cv::String to `cv::imread(cv::String const&, int)'
 C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:10: undefined reference to cv::namedWindow(cv::String `cv::namedWindow(cv::String const&, int)'
C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:11: undefined reference tocv::imshow(cv::String to `cv::imshow(cv::String const&, cv::_InputArray const&)'
 C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:12: undefined reference to cv::waitKey(int)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv6StringC1EPKc':
`cv::waitKey(int)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringC1EPKc':
C:/OpenCV/sources/modules/core/include/opencv2/core/cvstd.hpp:625: undefined reference to cv::String::allocate(unsigned `cv::String::allocate(unsigned int)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv6StringD1Ev':
function `ZN2cv6StringD1Ev':
C:/OpenCV/sources/modules/core/include/opencv2/core/cvstd.hpp:667: undefined reference to cv::String::deallocate()'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv3MatD1Ev':
`cv::String::deallocate()'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv3MatD1Ev':
C:/OpenCV/sources/modules/core/include/opencv2/core/mat.inl.hpp:571: undefined reference to cv::fastFree(void*)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In functionZN2cv3Mat7releaseEv':
`cv::fastFree(void*)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv3Mat7releaseEv':
C:/OpenCV/sources/modules/core/include/opencv2/core/mat.inl.hpp:682: undefined reference to `cv::Mat::deallocate()'
 collect2.exe: error: ld returned 1 exit status
 CMakeFiles\OpenCVFirstDemo.dir\build.make:112: recipe for target 'OpenCVFirstDemo.exe' failed
 CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/OpenCVFirstDemo.dir/all' failed
 mingw32-make.exe[3]: * *** [OpenCVFirstDemo.exe] Error 1
 CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/OpenCVFirstDemo.dir/rule' failed
 mingw32-make.exe[2]:  *** [CMakeFiles/OpenCVFirstDemo.dir/all] Error 2
 mingw32-make.exe[1]:  *** [CMakeFiles/OpenCVFirstDemo.dir/rule] Error 2
 Makefile:117: recipe for target 'OpenCVFirstDemo' failed
 mingw32-make.exe: * *** [OpenCVFirstDemo] Error 2

2