CMake interesting but challenging

Hi! I usually write in about strictly coding issues, but lately I have been challenged in the area of CMake, a place I have never been. Basically I am trying to install OpenCV for Eclipse IDE. My due diligence on this problem has included VS binaries, and I am reluctant to move away from Eclipse to VS for several reasons. So, I started the installation with CMake and I get immediate errors that I don't understand getting, as I usually stick tight to the tutorial:

Initial recommended steps:

Requirements :
1
2
3
4
5
6
7
8
9
10
11
12
Download OpenCV source from github repo (extract it to a folder we will name opencv_src_folder)
Download and install MinGW (also add /bin folder to system path)
Download and install CMake
Steps :

Open CMake-gui

set src folder as opencv_src_folder
set build folder as opencv_src_folder/Mingw_build/
Hit configure and choose Eclipse CDT4 - MinGW MakeFile then next.
if configure successful , hit generate.


That's as far as I ever get -- incomplete config
Exit 1:

CMake Error at CMakeLists.txt:117 (project):
Failed to run MSBuild command:

C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe

to get the value of VCTargetsPath:

Microsoft (R) Build Engine version 4.0.30319.34209

[Microsoft .NET Framework, version 4.0.30319.34209]

Copyright (C) Microsoft Corporation. All rights reserved.



Build started 1/30/2018 5:32:16 PM.

Project "C:\opencv\new_build\CMakeFiles\3.10.2\VCTargetsPath.vcxproj" on node 1 (default targets).

C:\opencv\new_build\CMakeFiles\3.10.2\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Done Building Project "C:\opencv\new_build\CMakeFiles\3.10.2\VCTargetsPath.vcxproj" (default targets) -- FAILED.



Build FAILED.



"C:\opencv\new_build\CMakeFiles\3.10.2\VCTargetsPath.vcxproj" (default target) (1) ->

C:\opencv\new_build\CMakeFiles\3.10.2\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.



0 Warning(s)

1 Error(s)



Time Elapsed 00:00:00.16



Exit code: 1

Last edited on
Problem has narrowed down a good bit: I was able to "point" CMake's processor option to G++ and everything fell into place. The only thing left is a somewhat cryptic instruction the tutorial that when CMake is done with configuration and generation, to type "make" to finish up the installation. Problem is that the CMake's binary options only include CMake-gui and cmake and a few others. Nothing about plain vanilla "make". Thinking that the author meant "make" it seemed to rebuild the directory.

Q1:
In any event could somebody pl-ease tell me what "make" is or where to find it?

Q2:
Do I need to rebuild opencv as Gcc compiler? Eclipse is Gcc. Or should I force Eclipse into being G++ as it should be.
Last edited on
CMake doesn't build your code. That's the job of your build tool (here, make.) CMake is only there to provide make's input, in a way that's portable.

What is make:
https://www.gnu.org/software/make/

MSYS2/Cygwin/MinGW provide it, although it may have to be installed.

It is a command-line program; you will need to run it from a console. Here's an example of a 3-stage build using CMake that might be useful:
http://www.cplusplus.com/forum/beginner/215083/

Thank you so much. I'm on it.

One of my immediate problems is that I can't get the console program CMake to stay open. It closes after launch. No problem with cmake-gui.
You've got to type the name of the program into the command line. It's not interactive.
Ok, its gone really well doing a hello_world makefile project. Its time to build, and I get this error:

15:17:00 **** Incremental Build of configuration Default for project hello_world ****
make all 
Cannot run program "make": Launching failed
1
2
3
4
5
6
7
Error: Program "make" not found in PATH
PATH=[C:/Program Files/Java/jre1.8.0_161/bin/server;C:/Program Files/Java/jre1.8.0_161/bin;C:/Program Files/Java/jre1.8.0_161/lib/amd64;
C:\Program Files\Java\jdk-9.0.1\bin;C:\ProgramData\Oracle\Java\javapath; 
C:\cmake-3.10.2-win64-x64;C:\Program Files\CMake\bin;
C:\minGW\mingw64\bin; C:\Program Files\Java\jdk-9.0.1\bin;C:\Users\xxxx\Desktop]

15:17:00 Build Finished (took 28ms)


This is the same mystery I had in the first question. What/how do I use make?

Make is even a checkbox option in the build settings.
Last edited on
Looks like you're using MinGW:

See this:
https://stackoverflow.com/questions/42752721/mingw-64-ships-without-make-exe?rq=1

Apparently you are supposed to copy (or symlink, presumably) the 32-bit version of the program mingw-32-make.exe from elsewhere to C:\MinGW\MinGW64\bin\make.exe. Hopefully some version of it is on your computer - maybe do a search for it.
Last edited on
Scan of my system revealed mingw32-make.exe in C:\minGW\mingw64\bin.
Did copying it as suggested solve the problem?
Sorry for the delay to follow up. Success! The equivalent command to
make
is as above mingw32-make. I added it to the path. It is mingw32-make for both 32 and 64bit. I was able to build custom OpenCV library optimized for Eclipse makefiles. I had a couple of bumps along the way like the DNN module but was able to build without it. Thank you for your help!

The build was successful but am having a problem creating a simple executable. I have been looking everywhere for guidance.

Basically the opencv tutorial uses DisplayImage.cpp as source and some includes, in /DisplayImage. It also creates CMakeLists.txt. (below). Ive moved both of them from the DisplayImage directory and put them in the root of the build directory because I get an include error if I put the files into the suggested directory.
------------------------------------------------------------------------------
At this point I'll take the example running in the parent folder or displayimage folder. The include error does go away with the project in the parent folder. Its so simple but I cant see it!
CMakelists.txt
1
2
3
4
5
6
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} )

DisplayImage.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }
    Mat image;
    image = imread( argv[1], 1 );
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
    return 0;
}


How do I create an executable here?
My opencv library is completely built -- directory: c:\opencv_build.
Last edited on
Well, the heavy lifting is over. Somehow I figured out that the above status was ready for building an executable, when it wasn't. I noticed a conspicuous absence of an install directory in my CV build. SO on an educated guess I went to my build directory and executed
mingw32-make install and my screen blew up (in a good way) with an installed build including CV .h files all in one directory. I am working on the project but the heavy lifting is over.

Some questions to conclude:

1. why is it better to build your own binaries? In this case I was forced to because I refused to give up my Eclipse for VS

2. portability? w/ makefiles I can go back and forth between Windows and Linux op systems without reporting?

3. I went from downloading via github to a source file. Then cmake, configure then generate in source file. Then cmake/make the project to a target folder. Then, in the target folder mingw32-make install --> final product.

Is number 3 basically a test drive of how to make your own distribution?
Registered users can post here. Sign in or register to post.