Ask Your Question
0

Can't seem to use OpenCV

asked 2017-06-06 23:40:21 -0600

spaceman gravatar image

I have followed the instructions included in the documentation for installing OpenCV (several times, just to make sure), and yet I am still not able to link my code, which is written in C++. Are there better outlined steps I can follow?

For context, I am using g++ as my compiler (with Cygwin), and I have two C++ sources I am trying to link. I am running on a Windows 10 x64 machine. The actual .cpp sources compile fine, but the linker is having a heart attack.

Cheers!

edit retag flag offensive close merge delete

Comments

1

did you actually build the opencv libs for your compiler ? (you cannot use the prebuilt vs2015 ones)

berak gravatar imageberak ( 2017-06-07 00:10:13 -0600 )edit

Really? Was not aware of that... I've tried building them, I'll do it again though. This is why I avoid libs as much as possible.

spaceman gravatar imagespaceman ( 2017-06-07 08:32:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-07 02:29:27 -0600

lohachan0108 gravatar image

updated 2017-06-07 02:30:56 -0600

Hello. As per your question, I guess that you have installed OpenCV but are having problem while compiling and running the code. Here are steps you should follow. 1. Name your .cpp file as main.cpp 2. Create a .txt file and name it as CMakeLists.txt 3. In the CmakeLists.txt file paste the following lines

" cmake_minimum_required(VERSION 2.6) cmake_policy(SET CMP0012 NEW) PROJECT(project)

#Requires OpenCV FIND_PACKAGE(OpenCV 3.0.0 REQUIRED) MESSAGE("OpenCV version : ${OpenCV_VERSION}")

include_directories(${OpenCV_INCLUDE_DIRS}) link_directories(${OpenCV_LIB_DIR}) ADD_EXECUTABLE(app main.cpp) TARGET_LINK_LIBRARIES(app ${OpenCV_LIBS}) " without the doublequotes at the start and the end. Save the file.

  1. Now open the terminal and go to the directory where these file are stored. And in the terminal type "cmake ." ,without the doublequotes.
  2. Now in the terminal type "make" and press enter.
  3. It will compile and generate an executable file name app
  4. Execute the app file using ./app
  5. Hope it helps.
edit flag offensive delete link more

Comments

@lohachan0108 Can you add an instruction or two for compiling with multiple sources? I'm new to CMake.

spaceman gravatar imagespaceman ( 2017-06-12 23:01:49 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-06-06 23:40:21 -0600

Seen: 254 times

Last updated: Jun 07 '17