Windows下GHCi无法加载lmdb.dll:Haskell LMDB绑定库调用异常求助
Hey there, let's tackle this problem step by step—your error is a classic case of GHCi not finding the native LMDB DLL, plus a potential mismatch in how the Haskell bindings were linked to the library. Here's what you can do to fix it, tailored to your Windows 7 x64, Haskell Platform 8.0.2, and vcpkg setup:
1. Add LMDB's DLL path to your system PATH
vcpkg installs the 64-bit lmdb.dll in C:\vcpkg\installed\x64-windows\bin (adjust the path if you installed vcpkg elsewhere). GHCi relies on the system PATH to locate native DLLs, so you need to add this directory:
- Right-click "Computer" → Properties → Advanced System Settings → Environment Variables
- Under System Variables, find
PATH, click Edit, and add the full path to the bin folder - Restart your terminal/IDE—this is crucial for the PATH change to take effect
2. Recompile the Haskell LMDB bindings with explicit library paths
Sometimes Cabal doesn't automatically pick up vcpkg's installed libraries. Force it to use the vcpkg LMDB by specifying the include and lib directories during installation:
cabal install lmdb --extra-include-dirs=C:\vcpkg\installed\x64-windows\include --extra-lib-dirs=C:\vcpkg\installed\x64-windows\lib
This ensures the bindings are compiled against the correct 64-bit LMDB library from vcpkg, avoiding conflicts with any 32-bit versions that might be lurking on your system.
3. Manually load the DLL in GHCi (if PATH changes don't stick)
If restarting your terminal still doesn't work, you can directly load the DLL in GHCi before using your module:
Prelude> import System.Win32.DLL Prelude System.Win32.DLL> loadLibrary "C:\\vcpkg\\installed\\x64-windows\\bin\\lmdb.dll"
Once it loads successfully, import your Persistence module and try calling lmdb_version again.
4. Verify 32/64-bit compatibility
Double-check that your Haskell Platform is 64-bit—if it's 32-bit, it won't work with the x64-windows LMDB from vcpkg. Run this command in your terminal:
ghc --version
Look for x86_64 in the output (that means 64-bit). If you see i386, you'll need to:
- Uninstall the x64 LMDB via vcpkg:
vcpkg remove lmdb:x64-windows - Install the 32-bit version:
vcpkg install lmdb:x86-windows - Recompile the Haskell bindings with the 32-bit paths
5. Clean old Cabal caches
Stale compilation artifacts can cause weird symbol errors. Clear them out and reinstall the bindings fresh:
cabal clean rmdir /s /q C:\Users\thanhdo\AppData\Roaming\cabal\x86_64-windows-ghc-8.0.2\lmdb-* cabal install lmdb --extra-include-dirs=C:\vcpkg\installed\x64-windows\include --extra-lib-dirs=C:\vcpkg\installed\x64-windows\lib
Work through these steps one by one, and you should be able to get the LMDB bindings working in GHCi without those DLL and symbol errors.
内容的提问来源于stack exchange,提问作者T. Do

