Linking c++ dll with Haskell-Platform on Windows, outputs 'undefined reference'

∥☆過路亽.° 提交于 2019-11-30 17:39:00

问题


I am a Haskell enthusiast and have got stuck upon compiling my little Haskell program on Windows. My program uses the iconv package, which in turn uses the foreign library written in c/c++. To make things work I have :

  • Run GNU-Iconv setup and added its 'bin' folder, where 'libiconv-2.dll' and 'libiconv2.dll' are located, to the PATH variable.
  • Extracted and copied 'LibIconv developer files' to the 'mingw' folder of Haskell Platform location.
  • Then 'cabal install iconv' compiles and I have the cabal package installed.

Now, when I try to build my module in Leksah, I get the following message from 'GHC':

Building norms-parser-0.0.1...
Linking dist\build\norms-parser\norms-parser.exe ...
C:\Documents and Settings\kdv\Application Data\cabal\iconv-0.4.1.0\ghc-7.0.4/libHSiconv-0.4.1.0.a(hsiconv.o):hsiconv.c:(.text+0x7): undefined reference to `_imp__libiconv_open'
C:\Documents and Settings\kdv\Application Data\cabal\iconv-0.4.1.0\ghc-7.0.4/libHSiconv-0.4.1.0.a(hsiconv.o):hsiconv.c:(.text+0x17): undefined reference to `_imp__libiconv'
C:\Documents and Settings\kdv\Application Data\cabal\iconv-0.4.1.0\ghc-7.0.4/libHSiconv-0.4.1.0.a(hsiconv.o):hsiconv.c:(.text+0x27): undefined reference to `_imp__libiconv_close'
collect2: ld returned 1 exit status

With 'GHCi',I face an issue too:

ghc.exe: unable to load package `iconv-0.4.1.0'
ghc.exe: C:\Documents and Settings\kdv\Application Data\cabal\iconv-0.4.1.0\ghc-    7.0.4\HSiconv-0.4.1.0.o: unknown symbol `__imp__libiconv_open'

I think the probable solution is in having the right setup of c/c++ header files to 'mingw' folder and setting PATH variables to 'lib' files, but I have little knowledge about it, so any help will be much appreciated.


回答1:


Installing libiconv is a little tricky on Windows.

  1. Download libiconv binary and developer files from it site here
  2. Unzip both packages over mingw folder, which is inside your Haskell Platform folder.
  3. Download cabal package for Iconv latest version for the moment
  4. Edit iconv.cabal file, so lines with include-dirs and extra-lib-dirs will looks like

    include-dirs:    cbits, "C:\\HaskellPlatform\\2013.2.0.0\\mingw\\include"
    extra-lib-dirs:  "C:\\HaskellPlatform\\2013.2.0.0\\mingw\\lib"
    

notice the double dashes in windows path, and edit it to your path of Haskell Platform.

  1. Edit iconv.cabal file, there is a line with if os(darwin) || os(freebsd), change it to if os(darwin) || os(freebsd) || os(windows)
  2. Thats it, now you can run cabal install command from iconv pachage dir


来源:https://stackoverflow.com/questions/8972662/linking-c-dll-with-haskell-platform-on-windows-outputs-undefined-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!