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

编译Darknet(YOLO目标检测)时遭遇OpenCV相关编译致命错误

Fix Darknet Compilation Errors with OpenCV (3.4.0 & 4.x+)

Hey there, let's work through this Darknet compilation issue with your OpenCV setup. First, let's look at the error you ran into:

gcc -Iinclude/ -Isrc/ -DOPENCV pkg-config --cflags opencv -DGPU -I/usr/local/cuda-9.1/include/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -c ./src/gemm.c -o obj/gemm.o
In file included from /usr/local/include/opencv2/core/types_c.h:59:0, from /usr/local/include/opencv2/core/core_c.h:48, from /usr...

This points to a header file resolution issue between Darknet and your OpenCV 3.4.0 installation. Here's how to fix it, plus key notes for OpenCV 4.x+ users:

For OpenCV 3.4.0 Users

  • Verify pkg-config is targeting the right OpenCV version
    Sometimes system-wide pkg-config might be pointing to an older OpenCV install by mistake. Run this to check:

    pkg-config --modversion opencv
    

    If it doesn't return 3.4.0, force it to use your compiled version by setting the pkg-config path:

    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    

    (Adjust the path if you installed OpenCV to a custom directory.)

  • Tweak the Darknet Makefile
    Open the Makefile in your Darknet root folder and make these changes:

    1. Ensure OPENCV=1 is uncommented (it looks like you have -DOPENCV enabled, but double-check the Makefile's top-level config).
    2. Replace the pkg-config --cflags opencv call with either pkg-config --cflags opencv3 (some systems name OpenCV 3's config this way) or manually specify the header paths:
      CPPFLAGS+= -I/usr/local/include/opencv2 -I/usr/local/include
      
    3. Update the linker flags to explicitly link OpenCV libraries:
      LDFLAGS+= -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs
      
  • Clean and recompile
    Wipe old build artifacts first to avoid conflicts:

    make clean
    

    Then start the compile again:

    make
    

Critical Notes for OpenCV 4.x+ Users

If you ever upgrade to OpenCV 4 or later, C++11 support is mandatory—skip this and you'll hit fatal compilation errors. Here's how to add it:

  • Edit the Darknet Makefile to add -std=c++11 (or higher, like -std=c++14) to your compiler flags:
    CFLAGS+= -std=c++11
    
  • Also, note that OpenCV 4's pkg-config config is usually named opencv4, so update the Makefile's pkg-config calls from opencv to opencv4 to pull the correct headers and libraries.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:26:32