Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This issue occurred when I was cross compiling #1136

Open
LouieLumi opened this issue Dec 22, 2023 · 3 comments
Open

This issue occurred when I was cross compiling #1136

LouieLumi opened this issue Dec 22, 2023 · 3 comments

Comments

@LouieLumi
Copy link

Description

Steps to Reproduce

7761632972260ca72e07f0969a5d451f

Your Environment

  • Operating System and version: MacOS 14
  • OpenCV version used:4.8.1
  • How did you install OpenCV?:Homebrew
  • GoCV version used:0.35.0
  • Go version:1.21.5
  • Did you run the env.sh or env.cmd script before trying to go run or go build?
@LouieLumi
Copy link
Author

arm mac => linux amd64

@HunterAP23
Copy link

HunterAP23 commented Mar 17, 2024

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
Copy link

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
<choose x86_64-w64-mingw32-gcc-posix from the list>

$ sudo update-alternatives --config x86_64-w64-mingw32-g++
<choose x86_64-w64-mingw32-g++-posix from the list>
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants