1
votes

I have just installed OpenCV and have been trying to execute an example to DsiplayImage. I get the following error while trying to "cmake ."

~/Desktop$ cmake . CMake Error at CMakeLists.txt:5 (target_link_libraries): Cannot specify link libraries for target "DisplayImage" which is not built by this project.

-- Configuring incomplete, errors occurred!

The following is the actual code: displayimage.cpp

#include <cv.h>
#include <highgui.h>
using namespace cv;

int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1], 1 );

  if( argc != 2 || !image.data )
    {
      printf( "No image data \n" );
      return -1;
    }

  namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
  imshow( "Display Image", image );

  waitKey(0);

  return 0;
}

CmakeLists.txt

cmake_minimum_required(VERSION 2.8)
project( displayimage )
find_package( OpenCV REQUIRED )
add_executable( displayImage displayimage )
target_link_libraries( displayimage ${OpenCV_LIBS} )
1

1 Answers

3
votes

it should be

cmake_minimum_required(VERSION 2.8)
PROJECT( displayimage )
FIND_PACKAGE( OpenCV REQUIRED )
ADD_EXECUTABLE( displayimage displayimage.cpp )
TARGET_LINK_LIBRARIES( displayimage ${OpenCV_LIBS} )

I tried this code on my machine and it works. maybe its because all commands have to be capital letters!!no idea but it works cheers :)