在 Windows 11 上使用 Go 和 gocv for OpenCV 无法找到标头 opencv.hpp,即使设置了 CGO_CXXFLAGS

问题描述 投票:0回答:1

运行时

go run
,未找到。 但是当列出
dir
时,标题就在那里......

PS C:\Users\phili\SourceCode\goopencv> set CGO_CPPFLAGS="-IC:/Users/phili/SourceCode/opencv/build/include"

PS C:\Users\phili\SourceCode\goopencv> go run -tags customenv "C:\Users\phili\go\pkg\mod\gocv.io\x\[email protected]\cmd\version\main.go"

# gocv.io/x/gocv
In file included from aruco.cpp:1:0:
aruco.h:5:10: fatal error: opencv2/opencv.hpp: No such file or directory
 #include <opencv2/opencv.hpp>
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.

/*        */

PS C:\Users\phili\SourceCode\goopencv> dir C:\Users\phili\SourceCode\opencv\build\include\opencv2\opencv.hpp

    Directory: C:\Users\phili\SourceCode\opencv\build\include\opencv2

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         9/27/2023   9:54 AM           3558 opencv.hpp

PS C:\Users\phili\SourceCode\goopencv>

我也尝试在 MSYS2 中安装并收到不同的错误:

phili@PhilBook3 UCRT64 ~/gocv
$ go run "C:\msys64\ucrt64\lib\go\pkg\mod\gocv.io\x\[email protected]\cmd\version\main.go"

# gocv.io/x/gocv
C:\Users\phili\go\pkg\mod\gocv.io\x\[email protected]\calib3d_string.go:3:9: undefined: CalibFlag
C:\Users\phili\go\pkg\mod\gocv.io\x\[email protected]\calib3d_string.go:29:9: undefined: CalibCBFlag
...
C:\Users\phili\go\pkg\mod\gocv.io\x\[email protected]\core_string.go:159:9: too many errors

我只是想尽可能让它在 Windows 上运行。

如果有人有任何想法,那就太好了!

opencv go msys2 windows-11 gocv
1个回答
0
投票

同样的错误:

"C:\Program Files\Go\bin\go.exe" run D:\Golang\opencv\test.go
gocv.io/x/gocv
In file included from aruco.cpp:1:
aruco.h:5:10: fatal error: opencv2/opencv.hpp: No such file or directory
5 | #include <opencv2/opencv.hpp>
|          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.

解决方案:

copy your opencv/build/install/inlude/opencv2  directory to \go\pkg\mod\gocv.io\x\[email protected]  directory then error disappear
© www.soinside.com 2019 - 2024. All rights reserved.