Ask Your Question

Building OpenCV with MinGW (gcc 7.1.0 and cmake 3.9.0)-> windres.exe: unknown option -- W

asked 2017-07-23 14:38:00 -0600

DJUego gravatar image


Windows 10 x64

I try to build (default options) the current opencv master (2017/07/23) in MinGW (Mingw-builds, msys2) and i get;

> make
[  2%] Built target zlib
[  5%] Built target libtiff
[  8%] Built target libjpeg
[ 16%] Built target libwebp
[ 19%] Built target libjasper
[ 20%] Built target libpng
[ 25%] Built target IlmImf
[ 31%] Built target libprotobuf
[ 32%] Built target opencv_core_pch_dephelp
[ 32%] Built target pch_Generate_opencv_core
[ 32%] Building RC object modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj
v:\MinGW-Builds\mingw64\bin\windres.exe: unknown option -- W
Usage: v:\MinGW-Builds\mingw64\bin\windres.exe [option(s)] [input-file] [output-file]
 The options are:
  -i --input=<file>            Name input file
  -o --output=<file>           Name output file
  -J --input-format=<format>   Specify input format
  -O --output-format=<format>  Specify output format
  -F --target=<target>         Specify COFF target
     --preprocessor=<program>  Program to use to preprocess rc file
     --preprocessor-arg=<arg>  Additional preprocessor argument
  -I --include-dir=<dir>       Include directory when preprocessing rc file
  -D --define <sym>[=<val>]    Define SYM when preprocessing rc file
  -U --undefine <sym>          Undefine SYM when preprocessing rc file
  -v --verbose                 Verbose - tells you what it's doing
  -c --codepage=<codepage>     Specify default codepage
  -l --language=<val>          Set language when reading rc file
     --use-temp-file           Use a temporary file instead of popen to read
                               the preprocessor output
     --no-use-temp-file        Use popen (default)
  -r                           Ignored for compatibility with rc
  @<file>                      Read options from <file>
  -h --help                    Print this help message
  -V --version                 Print version information
FORMAT is one of rc, res, or coff, and is deduced from the file name
extension if not specified.  A single file name is an input file.
No input-file is stdin, default rc.  No output-file is stdout, default rc.
v:\MinGW-Builds\mingw64\bin\windres.exe: supported targets: pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 elf64-l1om elf64-k1om pe-i386 pei-i386 elf32-i386 elf32-iamcu elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
modules/core/CMakeFiles/opencv_core.dir/build.make:1642: recipe for target `modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1
CMakeFiles/Makefile2:1512: recipe for target `modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:162: recipe for target `all' failed
make: *** [all] Error 2

Any idea? Thanks in advance!


edit retag flag offensive close merge delete


It was good in 3.2.0... go back to 3.2.0 and make an issue@berak can you compile opencv 3.3.0-rc using mingw?

LBerger gravatar imageLBerger ( 2017-07-23 15:58:17 -0600 )edit

yes, but using cmake 3.5 here

berak gravatar imageberak ( 2017-07-24 07:18:26 -0600 )edit

any other solutions? I can't build with Cmake 3.5, 3.9, 2.8.7 or others. Supposedly it works with 2.8.1 but some modules I want to build require 2.8.7 or higher. I have no idea what to edit to overcome this problem/

edit. Ok it seems that disabling precompiled headers helps (mingw+cmake 3.5)

p310 gravatar imagep310 ( 2017-07-25 04:53:55 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2017-08-16 00:21:55 -0600

larryluo619 gravatar image

updated 2017-08-16 00:23:35 -0600

I also had this issue when I compiled OpenCV3.3 source code for Qt. Then I found the hint here(

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ If you have the following error : ... windres.exe: unknown option -- W ...

try this : in cmake uncheck ENABLE_PRECOMPILED_HEADERS

If, in the file opencv/sources/modules/videoio/src/cap_dshow.cpp, you have the following error : 'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' was not declared in this scope ...

try this :put the following line: #define NO_DSHOW_STRSAFE, before the line : #include "DShow.h"


Following above hints, it's OK at last.

My envirement: Whindows 7/10 64bit, Cmake 3.9.1, Qt5.9.1

edit flag offensive delete link more


Hello, thanks, you save my day and most of my night. As DJUego asks, can you explain what could be the "consequences (collateral effects) of disabling precompiled headers"?

virgiled gravatar imagevirgiled ( 2017-09-21 14:06:53 -0600 )edit

@virgiled and @DJUego For precompiled headers see here. The build process will be just slower without precompiled headers.

Eduardo gravatar imageEduardo ( 2017-10-10 13:36:33 -0600 )edit

ok, I see; tx very much for this precision @Eduardo.

virgiled gravatar imagevirgiled ( 2017-10-10 13:38:37 -0600 )edit

answered 2017-07-26 06:51:02 -0600

DJUego gravatar image

Hi! Thank you for your answers, guys. I can confirm that disabling precompiled headers (in CMake) works! Thank you for the hint, p310!! I am using cmake 3.9.0.

I have other problems with building but i think they are not related with this. I will open a new question about them. In a related note, What are the consequences (collateral effects) of disabling precompiled headers? Thanks in advance!


edit flag offensive delete link more

Question Tools



Asked: 2017-07-23 14:38:00 -0600

Seen: 8,351 times

Last updated: Aug 16 '17