学习OpenCV3:MinGW编译OpenCV到vs_version.rc.obj处出错


1. 错误描述

gcc: error: long: No such file or directory

1
2
3
4
5
6
[ 65% ] Building RC object modules/world/CMakeFiles/opencv_world.dir/vs_version.rc.obj
gcc: error: long: No such file or directory
C:\Mingw-w64\mingw32\bin\windres.exe: preprocessing failed.
mingw32-make[2]: *** [modules\world\CMakeFiles\opencv_world.dir\build.make:11240: modules/world/CMakeFiles/opencv_world.dir/vs_version.rc.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:4789: modules/world/CMakeFiles/opencv_world.dir/all] Error 2
mingw32-make: *** [Makefile:179: all] Error 2

2. 分析

??打开modules\world\CMakeFiles\opencv_world.dir\build.make的第11240行发现如下内容,可发现错误原因是未成功生成vs_version.rc.obj。

1
2
3
4
modules/world/CMakeFiles/opencv_world.dir/vs_version.rc.obj: modules/world/CMakeFiles/opencv_world.dir/flags.make
modules/world/CMakeFiles/opencv_world.dir/vs_version.rc.obj: modules/world/vs_version.rc
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=D:\opencv\bulid_mingw\CMakeFiles --progress-num=$(CMAKE_PROGRESS_801) "Building RC object modules/world/CMakeFiles/opencv_world.dir/vs_version.rc.obj"
    cd /d D:\opencv\bulid_mingw\modules\world && C:\Mingw-w64\mingw32\bin\windres.exe -O coff $(RC_DEFINES) $(RC_INCLUDES) $(RC_FLAGS) D:\opencv\bulid_mingw\modules\world\vs_version.rc CMakeFiles\opencv_world.dir\vs_version.rc.obj

3. 解决方法

??根据build.make中的错误行,自己修改编译命令,手动生成vs_version.rc.obj,并重新mingw32-make。

1
2
cd /d D:\opencv\bulid_mingw\modules\world
C:\Mingw-w64\mingw32\bin\windres.exe D:\opencv\bulid_mingw\modules\world\vs_version.rc -O coff CMakeFiles\opencv_world.dir\vs_version.rc.obj

编译命令

生成vs_version.rc.obj

重新mingw32-make