LumiGuide / haskell-opencv

Haskell binding to OpenCV-3.x
Other
154 stars 44 forks source link

Windows installation: unknown symbol 'inline_c_OpenCV_Internal_Exception' #71

Open tmh2211 opened 7 years ago

tmh2211 commented 7 years ago

Hi Guys, I want to use your library for my bachelor project and therefor I'm trying to install it on windows.

I downloaded the opencv version 3.1 for Windows and extracted it to C:\opencv. Then I created the following pc-File: Name: opencv Description: Library for machine vision Version: 3.1.0 CFlags: -IC:\\opencv\\build\\include Libs: -LC\\opencv\\build\\x64\\vc12\\lib -lopencv_world310 Next I cloned your repository and tried to install it via:

cabal install opencv.cabal

This works until the compilation of OpenCV.Internal.Core.Types.Mat. There I get the following error:

`[36 of 70] Compiling OpenCV.Internal.Core.Types.Mat ( src\OpenCV\Internal\Core\Types\Mat.hs, dist\dist-sandbox-800a0dac\build\OpenCV\Internal\Core\Types\Mat.o )

ghc.exe: dist/dist-sandbox-800a0dac\build\OpenCV\Internal\Exception.o: unknown symbol inline_c_OpenCV_Internal_Exception_1_2402dbf3aea4f7f79392b71ed42618962a22e9aa' cabal: Error: some packages failed to install: opencv-0.0.0 failed during the building phase. The exception was: ExitFailure 1

My ghc version is: 7.10.3

Note: I'm not an expert on building such projects - especially C - so I'm pretty sure I did something wrong :D.

Thanks for your help

basvandijk commented 7 years ago

Hi @tmh2211 , great to hear you want to use haskell-opencv for your bachelor project and that you are trying to get it to build on Windows. We haven't tried building it on Windows yet so it would be great to get support for that!

Unfortunately I can't help you with your problem since I don't have a Windows machine. Maybe try googling for similar problems.

Chuck-Aguilar commented 7 years ago

I don't have either Window. But I could recommend:

1- To use stack. There you'll have the stack.yaml and the your-project.cabal It works fine for me. 2- See here: https://github.com/LumiGuide/haskell-opencv/issues/1 Maybe you can get some idea there.

tmh2211 commented 7 years ago

Thanks for your replies. Had the same issue with stack. Maybe I'll just switch to linux.

Chuck-Aguilar commented 7 years ago

It would be a safe and healthy choice :joy:

HotCat commented 1 year ago

I successfully build 0.0.2.1 from source on MinGW with stack's buildin MinGW environment

during the building process, I encounted 'undefined symbol __ZdlPvm' while building OpenCV/Core/Types/Rect. It was caused by Template Haskell that can not link stdc++-6.dll. So in opencv.cabal at ghc-options tag, add -lstdc++ to solve the problem

then I use stack to create a new project, on stack.yaml I set lts-13.25. setup environment variable PKG_CONFIG_PATH pointing to opencv.pc, execute stack build

copy paste an highgui example program from opencv source directory to main.hs, stack build agian

copy libstdc++-6.dll from msys provided by stack to the current directory, so that you can execute stack exec Your-program

HotCat commented 1 year ago

additional comment, I recommended to build opencv from source on MinGW. I download opencv-3.4.2 from github, use stack to create an new project, specific lts-13.25 or any other lts equal or greater than lts-10.2 is ok.

then I should use stack's buildin gcc to compile opencv source

I invoke stack exec -- pacman -S mingw-w64-x86_64-make to install make utility, and so is cmake, stack exec -- pacman -S mingw-w64-x86_64-cmake

I invoke stack exec -- sh, this put you in stack's current(lts-13.25) shell environment

cd to opencv preconfigured build directory

cmake-gui -DCMAKE_MAKE_PROGRAM=path to configurate the opencv build parameters, generate the makefile

mingw32-make -j4; mingw32-make install

HotCat commented 1 year ago

I also successfully build under lts-18.28 on win10, I can not help to share some tips, I use stack doing the whole jobs

  1. repa could be the problem, you should download the whole repa-3.4.1.5 source and specific it under packages section in stack.yaml
  2. lts-18.28 use GHC 8.10.7, the Template Haskell do have a limitation on how many #sizeof can be included in a single hsc file. In my case, the limitation is only 5
  3. Stack build process will hang when the limitation is reached, So I manually distribute all the #sizeof in 'OpenCV.Internal.Core.Types.Constants' evenly on three files.
  4. when I try to build opencv using GHC 8.10.7 precluded gcc 9.2.0, I encount an 'internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.c:190: MapViewOfFileEx: Attempt to access invalid address'
  5. The solution is to issue 'setdllcharacteristics -n -d -f cc1.exe', 'setdllcharacteristics -n -d -f cc1plus.exe' to turn off ASLR flags in compilers