0

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 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

Still same error. Well the error is pointing to the last line of the CMakeLists.txt. Pls advice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.