Ask Your Question

Revision history [back]

I too have tried to build using what you have done, it didn't seem like it went anywhere, and I don't remember if by running cmake, as you did above, any good came of it. What I do now, though, is run cmake in individual folders on individual .cpp files as and when I need them. It is seems to be working well. But I have just started and don't know if the problem may amplify later. Any how I will describe what I do below.

Go the folder where the .cpp file is stored. Right click and open a new Document. Call it 'CMakeLists.txt'. It is very important that you call it precisely that. Open the document and paste this.

project( name_of_cpp )

find_package( OpenCV REQUIRED )

add_executable( name_of_cpp name_of_cpp )

target_link_libraries( name_of_cpp ${OpenCV_LIBS} )

Where you replace 'name_of_cpp ' with the name of your cpp file.

Next you open terminal and go the folder using cd. Once you are there type in 'cmake ." Note:there is a space between cmake and the '.' . After that type in 'make'. You should see an executable being formed. Some executables require you to parse it an image file from command line. If u have the image in the same folder then you can run the executable using

./name_of_file name_of_image.jpg

or else, you can pass the image using its relative position to the active folder by using /../../image.jpg I think it should lie somewhere in the parent folder for this to work. (correct me if wrong). and last way is to give the absolute address in relation to home.