hybridgroup / gocv

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, and OpenCV Contrib.
https://gocv.io
Other
6.62k stars 863 forks source link

This issue occurred when I was cross compiling #1136

Open LouieLumi opened 9 months ago

LouieLumi commented 9 months ago

Description

Steps to Reproduce

7761632972260ca72e07f0969a5d451f

Your Environment

LouieLumi commented 9 months ago

arm mac => linux amd64

HunterAP23 commented 6 months ago

I'm facing a similar issue, but when doing Linux host (WSL) with Windows target Operating System and version: Ubuntu 22.04.4 LTS (WSL2) OpenCV version used: 4.8.1 How did you install OpenCV?: Through package manager apt GoCV version used: 0.35.0 Go version: 1.22.1 linux/amd64

I have the relevant mingw64 package installed for cross-compiling. This is the command I'm using: CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o bin/my_file.exe my_file

This is the output I get:

# 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.

Not sure how to include the relevant opencv files in the build. In my case the opencv files that is not getting imported correctly are located in /usr/include/opencv4/opencv2

I updated the build command to use CGO_CPPFLAGS="-I/usr/local/include/opencv4" but now I get this error:

# gocv.io/x/gocv
In file included from /usr/local/include/opencv4/opencv2/core.hpp:3370,
                 from /usr/local/include/opencv4/opencv2/opencv.hpp:52,
                 from aruco.h:5,
                 from aruco.cpp:1:
/usr/local/include/opencv4/opencv2/core/utility.hpp:718:14: error: ‘recursive_mutex’ in namespace ‘std’ does not name a type
  718 | typedef std::recursive_mutex Mutex;
      |              ^~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/utility.hpp:63:1: note: ‘std::recursive_mutex’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
   62 | #include <mutex>  // std::mutex, std::lock_guard
  +++ |+#include <mutex>
   63 | #endif
/usr/local/include/opencv4/opencv2/core/utility.hpp:719:29: error: ‘Mutex’ is not a member of ‘cv’
  719 | typedef std::lock_guard<cv::Mutex> AutoLock;
      |                             ^~~~~
/usr/local/include/opencv4/opencv2/core/utility.hpp:719:29: error: ‘Mutex’ is not a member of ‘cv’
/usr/local/include/opencv4/opencv2/core/utility.hpp:719:34: error: template argument 1 is invalid
  719 | typedef std::lock_guard<cv::Mutex> AutoLock;
      |                                  ^
In file included from /usr/local/include/opencv4/opencv2/flann/kdtree_index.h:44,
                 from /usr/local/include/opencv4/opencv2/flann/all_indices.h:38,
                 from /usr/local/include/opencv4/opencv2/flann/flann_base.hpp:44,
                 from /usr/local/include/opencv4/opencv2/flann.hpp:48,
                 from /usr/local/include/opencv4/opencv2/opencv.hpp:65,
                 from aruco.h:5,
                 from aruco.cpp:1:
/usr/local/include/opencv4/opencv2/flann/heap.h: In static member function ‘static cv::Ptr<cvflann::Heap<T> > cvflann::Heap<T>::getPooledInstance(const HashableT&, int, int)’:
/usr/local/include/opencv4/opencv2/flann/heap.h:191:20: error: ‘Mutex’ in namespace ‘cv’ does not name a type
  191 |         static cv::Mutex mutex;
      |                    ^~~~~
/usr/local/include/opencv4/opencv2/flann/heap.h:192:33: error: ‘mutex’ was not declared in this scope
  192 |         const cv::AutoLock lock(mutex);
      |                                 ^~~~~
HunterAP23 commented 6 months ago

Actually I ended up solving the issues I mentioend through two things:

  1. Set all the mingw threads to posix instead of win32
    
    $ sudo update-alternatives --config i686-w64-mingw32-gcc
    <choose i686-w64-mingw32-gcc-posix from the list>

$ sudo update-alternatives --config i686-w64-mingw32-g++ <choose i686-w64-mingw32-g++-posix from the list>

$ sudo update-alternatives --config x86_64-w64-mingw32-gcc

$ sudo update-alternatives --config x86_64-w64-mingw32-g++ ``` 2. Include the directory to the Windows OpenCV DLL's Since I'm on WSL I can access these files through `/mnt/DRIVE_LETTER/path/to/libraries` so my final command became ``` CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1 CGO_CPPFLAGS="-I/usr/local/include/opencv4" CXXFLAGS="-std=c++11" CGO_LDFLAGS="-L/mnt/c/opencv/build/install/x64/mingw/bin/" GOOS=windows GOARCH=amd64 go build -o bin/my_file.exe my_file.go ```