Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv 3.1 Undefined Reference

Here is my CMakeLists.txt:

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

Here is my DisplayImage.cpp:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>


using namespace cv;

int main(int argc, char** argv )
{

    Mat image;
    image = imread( argv[1], 1 );


    imshow("Display Image", image);

    waitKey(0);

    return 0;
}]

*Extra headers because I wanted to make sure I wasn't forgetting an include

cmake . works After running make:

[ 50%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
[100%] Linking CXX executable DisplayImage
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `main':
DisplayImage.cpp:(.text+0x5f): undefined reference to `cv::imread(cv::String const&, int)'
DisplayImage.cpp:(.text+0xd0): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::String::String(char const*)':
DisplayImage.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::String::~String()':
DisplayImage.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
make[2]: *** [DisplayImage] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2