Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cabal install pcre-light on windows. Extra-include-dirs/extra-lib-dirs not working

I'm using MinGW+MSYS,

I've added extra-include-dirs, extra-lib-dirs, but nothing seems to be helping cabal find the pcre library. Here are some command lines I've tried, and some sample output below it.

cabal install pcre-light --extra-include-dirs='C:\Program Files (x86)\GnuWin32\include' --extra-lib-dirs='C:\Program Files (x86)\GnuWin32\lib'
cabal install pcre-light --extra-include-dirs='/C/Program Files (x86)/GnuWin32/include' --extra-lib-dirs='/C/Program Files (x86)/GnuWin32/lib'
cabal install pcre-light --extra-include-dirs="/C/Program Files (x86)/GnuWin32/include" --extra-lib-dirs="/C/Program Files (x86)/GnuWin32/lib"

and I keep getting something along these lines:

Resolving dependencies...
Notice: installing into a sandbox located at C:\Users\user\src\DBSite\dbsite\.cabal-sandbox
Configuring pcre-light-0.4.0.3...
Failed to install pcre-light-0.4.0.3
Last 10 lines of the build log ( C:\Users\user\src\DBSite\dbsite\.cabal-sandbox\logs\pcre-light-0.4.0.3.log ):
[1 of 1] Compiling Main             ( C:\Users\user\AppData\Local\Temp\pcre-light-0.4.0.3-9072\pcre-light-0.4.0.3\dist\dist-sandbox-6710ae14\setup\setup.hs, C:\Users\user\AppData\Local\Temp\pcre-light-0.4.0.3-9072\pcre-light-0.4.0.3\dist\dist-sandbox-6710ae14\setup\Main.o )
Linking C:\Users\user\AppData\Local\Temp\pcre-light-0.4.0.3-9072\pcre-light-0.4.0.3\dist/dist-sandbox-6710ae14\setup\setup.exe ...
Configuring pcre-light-0.4.0.3...
setup.exe: Missing dependency on a foreign library:
* Missing C library: pcre
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
cabal.exe: Error: some packages failed to install:
pcre-light-0.4.0.3 failed during the configure step. The exception was:
ExitFailure 1
like image 661
jgon Avatar asked Oct 09 '14 21:10

jgon


2 Answers

I really need to answer this problem since I suppose that a lot of people suffered from it. Just be clear for my system specification: Windows 7 64-bit, GHC 7.8.3 64-bit, cabal 1.20.0.3

Possible failure reasons:

1. missing C library

2.32-bit library is incompatible with 64-bit GHC.

You need to do:

1. A kind company airesoft built pcre with Microsoft Visual Studio 2008. Go to http://www.airesoft.co.uk/pcre to download the pcre you want or click http://www.airesoft.co.uk/files/pcre/pcre-8.33.zip to download 8.33. (Can somebody upload it to sourceforge?)

2. Change the file name pcre3.lib to pcre.lib and pcreposix3.lib to pcreposix.lib(I suppose this file is actually not needed but just in case.) I copied the file instead renaming it directly, but I think both ways are fine.

3. Depending 32 or 64-bit GHC, you need to specify the extra library and include. pcre-light requires pcre.h and pcre.lib. On my machine I just run

cabal install pcre-light --extra-lib-dirs=E:\\DOWNLOAD\\pcre-8.33\\lib\\x64 --extra-include-dirs=E:\\DOWNLOAD\\pcre-8.33\\inc

If your GHC is 32-bit you just remove the \\x64 in the above command

4. Of course, you need to add pcre3.dll into your system library path. I just copied it to C:\Windows\System32 directory. (I am not sure whether you need to rename it to pcre.dll, keep both in case. Make sure you choose the right file since 32-bit dll will crash on 64-bit machine and vice versa) Open your GHCi you should be able to import Text.Regex.PCRE.Light and try to invoke some functions.

I will try to merge the files into the pcre-light package inside it if possible. Good luck

like image 132
Song Zhang Avatar answered Nov 13 '22 19:11

Song Zhang


It should be a lot easier to install pcre-light nowadays on Windows if you do the following:

  • Install MSYS2 and install the pcre package by running pacman -S mingw-w64-i686-pcre (for 32-bit Windows) or pacman -S mingw-w64-x86_64-pcre (for 64-bit Windows).
  • Make sure you have GHC 7.10.3 or later. (Earlier versions come bundled with an outdated version of MinGW that wouldn't work well with MSYS2.)
  • Make sure you install pcre-light-0.4.0.4 or later with cabal install pcre-light-0.4.0.4. (Earlier versions wont't configure the extra dependencies automatically, which would require you to manually set --extra-lib-dirs and --extra-include-dirs flags.)

That's it!

like image 2
Ryan Scott Avatar answered Nov 13 '22 18:11

Ryan Scott