MinGW Compilers on Windows

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

MinGW Compilers on Windows

Kevan Hashemi
Greetings,

I'm new to CMake, so please forgive this basic question.

I'd like to use CMake to build OpenCV on Windows 7 using the C and C++ compilers that come with my
installation of MinGW. I compile all my other code with GCC compilers, from the command line of the
MSYS Bash shell, so I figure I can be certain to link OpenCV to my existing code if I compile with
GCC compilers.

I installed the Windows GUI of CMake and I told it to use the MinGW C and C++ compilers. I point
CMake at my OpenCV directory and a build directory. When I press configure, I get this error:

Selecting Windows SDK version to target Windows 6.1.7601.
CMake Error at CMakeLists.txt:64 (project):
Failed to run MSBuild command:
MSBuild.exe to get the value of VCTargetsPath:
The system cannot find the file specified
Configuring incomplete, errors occurred!
See also "F:/OpenCV/build/CMakeFiles/CMakeOutput.log".

If my understanding of CMake is correct, this error cannot not come directly from CMake, but rather
is caused by OpenCV asking for MSBuild. But I can find no instance of the styring "MSBuild" in the
OpenCV diretory tree. So my understanding must be wrong.

Why is CMake looking for MSBuild? Can I build on Windows using compilers of my choice?

Yours, Kevan

--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Konstantin Tokarev


08.12.2017, 22:16, "Kevan Hashemi" <[hidden email]>:

> Greetings,
>
> I'm new to CMake, so please forgive this basic question.
>
> I'd like to use CMake to build OpenCV on Windows 7 using the C and C++ compilers that come with my
> installation of MinGW. I compile all my other code with GCC compilers, from the command line of the
> MSYS Bash shell, so I figure I can be certain to link OpenCV to my existing code if I compile with
> GCC compilers.
>
> I installed the Windows GUI of CMake and I told it to use the MinGW C and C++ compilers. I point
> CMake at my OpenCV directory and a build directory. When I press configure, I get this error:
>
> Selecting Windows SDK version to target Windows 6.1.7601.
> CMake Error at CMakeLists.txt:64 (project):
> Failed to run MSBuild command:
> MSBuild.exe to get the value of VCTargetsPath:
> The system cannot find the file specified
> Configuring incomplete, errors occurred!
> See also "F:/OpenCV/build/CMakeFiles/CMakeOutput.log".
>
> If my understanding of CMake is correct, this error cannot not come directly from CMake, but rather
> is caused by OpenCV asking for MSBuild. But I can find no instance of the styring "MSBuild" in the
> OpenCV diretory tree. So my understanding must be wrong.
>
> Why is CMake looking for MSBuild? Can I build on Windows using compilers of my choice?

Of course, but you should choose a suitable generator, e.g. -G "MinGW Makefiles"

>
> Yours, Kevan
>
> --
> Kevan Hashemi, Electrical Engineer
> Physics Department, Brandeis University
> http://alignment.hep.brandeis.edu/
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake

--
Regards,
Konstantin
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Kevan Hashemi
Dear Konstantin,

> Of course, but you should choose a suitable generator, e.g. -G "MinGW Makefiles"

That makes perfect sense. Indeed, having selected "MinGW Makefiles" I don't evgen have to specify
the compilers, I can say "use native compilers". I also had to add MinGW/bin to the Winodws path, so
that CMake could run the native compilers and test them without launching MSYS.

Thank you, Kevan

--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Alan W. Irwin
On 2017-12-08 14:44-0500 Kevan Hashemi wrote:

> Dear Konstantin,
>
>> Of course, but you should choose a suitable generator, e.g. -G "MinGW
>> Makefiles"
>
> That makes perfect sense. Indeed, having selected "MinGW Makefiles" I don't
> evgen have to specify the compilers, I can say "use native compilers". I also
> had to add MinGW/bin to the Winodws path, so that CMake could run the native
> compilers and test them without launching MSYS.

If you need/prefer Unix tools provided by MSYS to build your software,
another possible generator you should look at is "MSYS Makefiles". We
never tried it before PLplot moved on to using MinGW-w64/MSYS2 (see
below), but I think "Unix Makefiles" might work for most MinGW/MSYS
build needs as well.

You certainly have those three generator choices for the modern
rewrite of the MinGW/MSYS platform, MinGW-w64/MSYS2
<https://github.com/msys2/msys2/wiki>.  In addition, MinGW-w64/MSYS2
provides many more free-software libraries than provided by MinGW/MSYS
so if your software has soft dependencies on lots of such libraries
(as in our PLplot case) the MinGW-w64/MSYS2 platform is far
preferred over the MinGW/MSYS platform.

Note some of the above statements are summaries of what has been
figured out by those on the PLplot development team who have access to
the Microsoft version of Windows.  I only have access to the Wine
version of Windows which works OK for MinGW/MSYS, but there is currently
a Wine bug that blocks my attempts to install MinGW-w64/MSYS2.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Kevan Hashemi
Dear Alan,

> If you need/prefer Unix tools provided by MSYS to build your software,
> another possible generator you should look at is "MSYS Makefiles".

Thank you for this suggestion.

The CMake configuration and generation of OpenCV completes without errors using "MinGW Makefiles". I
get one warning:

CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
CPACK_PACKAGE_VERSION does not match version provided by version.hpp header!

I assume that's a minor OpenCV-related error. When I "make", however, I enter some alternate shell
program with a Microsoft copyright at the top. I suspect this is because I have sh.exe in my MSYS
path, having seen this mentioned along the way, but if I remove sh.exe from the MSYS path, MSYS
won't even execute "ls", so I'm not sure how to fix that problem, nor do I understand why it is a
problem.

When I use "MSYS Makile", on the other hand, the OpenCV configuration and generation completes
without warnings. When I "make", off it goes, compiling. After editing MinGW's commctrl.h file to
solve an error related to OpenCV, the make completes and I have OpenCV built completely, which is
really cool. I looked through the Makefile and it is awesome.

I'm curious as to why the "make" for the MinGW generator does not work. But I have a working build
procedure, so I'm all set.

Yours, Kevan

--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Alan W. Irwin
On 2017-12-10 09:18-0500 Kevan Hashemi wrote:

> Dear Alan,
>
>> If you need/prefer Unix tools provided by MSYS to build your software,
>> another possible generator you should look at is "MSYS Makefiles".
>
> Thank you for this suggestion.
>
> The CMake configuration and generation of OpenCV completes without errors
> using "MinGW Makefiles". I get one warning:
>
> CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
> CPACK_PACKAGE_VERSION does not match version provided by version.hpp header!
>
> I assume that's a minor OpenCV-related error. When I "make", however, I enter
> some alternate shell program with a Microsoft copyright at the top. I suspect
> this is because I have sh.exe in my MSYS path, having seen this mentioned
> along the way, but if I remove sh.exe from the MSYS path, MSYS won't even
> execute "ls", so I'm not sure how to fix that problem, nor do I understand
> why it is a problem.
>
> When I use "MSYS Makile", on the other hand, the OpenCV configuration and
> generation completes without warnings. When I "make", off it goes, compiling.
> After editing MinGW's commctrl.h file to solve an error related to OpenCV,
> the make completes and I have OpenCV built completely, which is really cool.
> I looked through the Makefile and it is awesome.
>
> I'm curious as to why the "make" for the MinGW generator does not work. But I
> have a working build procedure, so I'm all set.

Hi Kevan:

Glad everything is working for you with "MSYS Makefiles".

Just to follow up on the "MinGW Makefiles" issue you ran into, it has
a test for sh.exe in the PATH, and if it finds it, it (rightly)
refuses to configure.  As far as I can tell using the "strings"
executable, mingw32-make.exe (the MinGW version of make you should use
with this generator) depends on sh.exe so I presume that means it has
different behaviour if sh.exe is in the PATH and the generator test
for "MinGW Makefiles" is designed to avoid that alternate behaviour.

So if you are further interested in the "MinGW Makefiles" generator,
you should remove all sh.exe versions from your PATH (including sh.exe
provided by raw Windows), get into a CMD environment, execute cmake
with the "MinGW Makefiles", and then build your software with

mingw32-make.exe

which internally uses CMD commands rather than Unix shell commands
to build software.  Note you should keep sh.exe out of your PATH not
only for the configuration stage, but also the build stage (to
avoid that presumed alternate behaviour of mingw32-make.exe in that
case).

For the Wine version of Windows I found this method of building
software was quicker than building using the "MSYS Makefiles"
generator.  I assume that is because the CMD environment is faster
than bash.exe. One complication for us is our PLplot test system
depends on bash scripts so requires bash.exe and other Unix tools to
be available.  So I tricked "MinGW Makefiles" into working fine with
our test system by putting a copy of MSYS in my path *but with sh.exe
removed*.  Thus, the build and test fundamentally depends on a CMD
environment, but most of the test commands executed in that
environment for us correspond to CMD executing bash.exe to run the
test scripts.

The above is from my own extensive but likely now dated experience
with MinGW/MSYS/Wine. My understanding from other's experience is the
MinGW-w64/MSYS2 platform has a similar "split personality" where you
have to very carefully distinguish between make versions from the
"mingw" versus "msys" repositories (with the former using CMD commands
to build and the latter using Unix shell commands to build) when using
the "MinGW Makefiles" generator versus the "MSYS Makefiles" generator.

I hope the above discussion allows you to have success with "MinGW
Makefiles" so you can compare its results with the corresponding "MSYS
Makefiles" results.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Kevan Hashemi
Dear Alan,

Thank you for your encouragement to use the "MinGW Makefiles" generator on Windows, and for pointing
out the mingw32-make alternative to just "make" in MSYS.

> So if you are further interested in the "MinGW Makefiles" generator,
> you should remove all sh.exe versions from your PATH (including sh.exe
> provided by raw Windows), get into a CMD environment, execute cmake
> with the "MinGW Makefiles", and then build your software with
>
> mingw32-make.exe

I installed the latest version of MinGW with MSYS on my 32-bit Windows 7 virtual machine (which is
running in VMBox on a MacOS 10.12.6 host computer). I open a CMD terminal (DOS prompt). I do not
move any sh.exe files. I run cmake with -G "MinGW Makefiles" for Executable_A. The configuration and
generation complete with no errors and only one warning. In the CMD terminal, I use mingw32-make.exe
to build Executable_A. The executable runs perfectly when linked dynamically to libraries I
previously built with "MSYS Makefiles".

I repeat the above process, but when it comes to the build itself, I switch from the CMD terminal to
the MSYS terminal, and use mingw32-make.exe instead of just "make" (as noted previously, "make"
takes me to an alternate shell with a Microsoft copyright). The build completes and Executable_A
runs just fine.

I rebuild my libraries with the "MinGW Makefiles" process, staying in the CMD terminal for both
stages. The CMake completes with a few minor warnings. The CMD build proceeds at about the same
speed as the MSYS build (you found the CMD build to be faster). When the build completes, I run
Executable_A linking dynamically to the new set of "MinGW Makefiles" libraries. The executable runs
perfectly.

Conclusion: Easiest way to get MinGW Makefile generation is to do it in the CMD terminal. After
that, you make with mingw32-make in eithger CMD or MSYS. Libraries compiled with either process are
compatible with one another at any stage of compiling or linking.

Yours, Kevan

--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

J Decker


On Fri, Dec 15, 2017 at 7:39 AM, Kevan Hashemi <[hidden email]> wrote:
Dear Alan,

Thank you for your encouragement to use the "MinGW Makefiles" generator on Windows, and for pointing out the mingw32-make alternative to just "make" in MSYS.

So if you are further interested in the "MinGW Makefiles" generator,
you should remove all sh.exe versions from your PATH (including sh.exe
provided by raw Windows), get into a CMD environment, execute cmake
with the "MinGW Makefiles", and then build your software with

mingw32-make.exe

I installed the latest version of MinGW with MSYS on my 32-bit Windows 7 virtual machine (which is running in VMBox on a MacOS 10.12.6 host computer). I open a CMD terminal (DOS prompt). I do not move any sh.exe files. I run cmake with -G "MinGW Makefiles" for Executable_A. The configuration and generation complete with no errors and only one warning. In the CMD terminal, I use mingw32-make.exe to build Executable_A. The executable runs perfectly when linked dynamically to libraries I previously built with "MSYS Makefiles".

I repeat the above process, but when it comes to the build itself, I switch from the CMD terminal to the MSYS terminal, and use mingw32-make.exe instead of just "make" (as noted previously, "make" takes me to an alternate shell with a Microsoft copyright). The build completes and Executable_A runs just fine.

I rebuild my libraries with the "MinGW Makefiles" process, staying in the CMD terminal for both stages. The CMake completes with a few minor warnings. The CMD build proceeds at about the same speed as the MSYS build (you found the CMD build to be faster). When the build completes, I run Executable_A linking dynamically to the new set of "MinGW Makefiles" libraries. The executable runs perfectly.

Conclusion: Easiest way to get MinGW Makefile generation is to do it in the CMD terminal. After that, you make with mingw32-make in eithger CMD or MSYS. Libraries compiled with either process are compatible with one another at any stage of compiling or linking.


I just want to throw out there, I use MinGW (with MingW Makefiles) wihtout MSYS just fine for most things.... including OpenCV which I tested first day and had no issues... but by then others had already commented.    All that requires is mingw(64).bin and cmake/bin in your path....

 
Yours, Kevan

--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: MinGW Compilers on Windows

Kevan Hashemi
> I just want to throw out there, I use MinGW (with MingW Makefiles) wihtout
> MSYS just fine for most things.... including OpenCV which I tested first
> day and had no issues... but by then others had already commented.    All
> that requires is mingw(64).bin and cmake/bin in your path....

Thank you, that's reassuring. I have not started on the 64-bit build yet. Kevan


--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake