You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译OpenCV 2.4.11遇内部编译器错误,寻求技术支持

解决OpenCV 2.4.11 MinGW编译时的内部编译器错误

问题背景

使用Windows 10 + MinGW 8.1.0 + CMake 3.24.3编译OpenCV 2.4.11,CMake配置完成后执行mingw32-make --debug,在生成core模块预编译头时触发内部编译器错误:

[ 19%] Generating precomp.hpp.gch/opencv_core_Release.gch
D:/opencv_mingw32/modules/core/precomp.hpp:202:1: internal compiler error: in gt_pch_note_object, at ggc-common.c:276
 }
 ^
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://sourceforge.net/projects/mingw-w64> for instructions.
mingw32-make[2]: *** [modules\core\CMakeFiles\pch_Generate_opencv_core.dir\build.make:75: modules/core/precomp.hpp.gch/opencv_core_Release.gch] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:1693: modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2

CMake配置信息如下:

General configuration for OpenCV 2.4.11 =====================================
  Version control:               unknown

  Platform:
    Host:                        Windows 10.0.19044 AMD64
    CMake:                       3.24.3
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/Tools/mingw64/bin/mingw32-make.exe
    Configuration:               Release

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Tools/mingw64/bin/c++.exe  (ver 8.1.0)
    C++ flags (Release):         -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -msse -msse2 -ffunction-sections -O2 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -msse -msse2 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  C:/Tool/mingw64/bin/gcc.exe
    C flags (Release):           -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -msse -msse2 -ffunction-sections -O2 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -msse -msse2 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      
    Linker flags (Debug):        
    Precompiled headers:         YES

  OpenCV modules:
    To be built:                 core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 androidcamera dynamicuda java python viz

  Windows RT support:            NO

  GUI: 
    QT:                          NO
    Win32 UI:                    YES
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.7)
    JPEG:                        build (ver 62)
    PNG:                         build (ver 1.5.12)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)

  Video I/O:
    Video for Windows:           YES
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES (prebuilt binaries)
      codec:                     YES (ver 55.18.102)
      format:                    YES (ver 55.12.100)
      util:                      YES (ver 52.38.100)
      swscale:                   YES (ver 2.3.100)
      gentoo-style:              YES
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    DirectShow:                  YES
    Media Foundation:            NO
    XIMEA:                       NO
    Intel PerC:                  NO

  Other third-party libraries:
    Use IPP:                     NO
    Use Eigen:                   NO
    Use TBB:                     NO
    Use OpenMP:                  NO
    Use GCD                      NO
    Use Concurrency              NO
    Use C=:                      NO
    Use Cuda:                    NO
    Use OpenCL:                  YES

  OpenCL:
    Version:                     dynamic
    Include path:                C:/opencv-2.4.11/3rdparty/include/opencl/1.2
    Use AMD FFT:                 NO
    Use AMD BLAS:                NO

  Python:
    Interpreter:                 C:/Tools/Python27/python.exe (ver 2.7.15)

  Java:
    ant:                         NO
    JNI:                         NO
    Java tests:                  NO

  Documentation:
    Build Documentation:         NO
    Sphinx:                      NO
    PdfLaTeX compiler:           NO
    Doxygen:                     NO

  Tests and samples:
    Tests:                       YES
    Performance tests:           YES
    C/C++ Examples:              NO

  Install path:                  C:/opencv/install

  cvconfig.h is in:              C:/opencv

解决方案

1. 禁用预编译头(最直接修复)

该错误是预编译头生成阶段的编译器内部异常,在CMake配置时关闭预编译头支持:

  • CMake GUI操作:点击Add Entry,添加名称ENABLE_PRECOMPILED_HEADERS,类型选BOOL,值设为OFF
  • 命令行操作:执行cmake -G "MinGW Makefiles" -DENABLE_PRECOMPILED_HEADERS=OFF ..
  • 重新生成Makefile后执行mingw32-make编译

2. 降级MinGW版本

OpenCV 2.4.11发布于2015年,与较新的MinGW 8.1.0存在兼容性冲突,推荐使用匹配的旧版本:

  • 选择MinGW 4.9.x或5.x版本,这类旧版编译器对旧代码的预编译头处理更稳定
  • 替换当前MinGW路径,重新配置CMake并编译

3. 调整编译优化参数

若需保留预编译头,可降低编译优化级别减少编译器负载:

  • 在CMake中修改CMAKE_CXX_FLAGS_RELEASE,将-O2改为-O1,同时移除-fomit-frame-pointer参数
  • 重新生成Makefile后编译

内容的提问来源于stack exchange,提问作者Valeria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 16:03:16