我正在使用 GHC 版本 7.6.1,按照文档中的步骤从 Haskell 库创建 DLL 以在 VBA 中使用它:GHC Docs 7.6.1 # 制作一个 DLL https://downloads.haskell.org/~ghc/7.6.1/docs/html/users_guide/win32-dlls.html#win32-dlls-create
我使用的文件与文档中的文件完全相同。在编译时,以下命令几乎按预期工作:
ghc -c Adder.hs
ghc -c StartEnd.c
第一个命令返回:
Adder.hs:7:1: Warning:
the 'stdcall' calling convention is unsupported on this platform,
treating as ccall
When checking declaration:
foreign export stdcall "adder" adder :: Int -> Int -> IO Int
我想应该没问题...
然而,最后一个命令ghc -shared -o Adder.dll Adder.o Adder_stub.o StartEnd.o
产生这个错误:
Adder_stub.h:1:19: fatal error: HsFFI.h: No such file or directory
compilation terminated.
这个线程 https://stackoverflow.com/questions/33272417/trying-to-export-a-haskell-lib-for-c指出我认识到 GHC 没有使用位于其中的头文件GHC-HOME/lib/include
。
该线程中的解决方案是使用 GHC 和选项-I [path to include-folder]
然而,当尝试它时(并查看 man 和文档),此版本的 GHC 没有这样的选项; 8.4.3 之前的较新版本中也没有。
When 阅读本文档 https://downloads.haskell.org/~ghc/7.6.1/docs/html/users_guide/modes.html我也遇到过应该可以使用该选项mk-dll
windows下生成dll;然而,根据我安装的 GHC 的手册页,即使我下载并安装了 Windows 64 位安装程序,也没有这样的选项。
然后我尝试将包含文件夹复制到其他位置;将第三个编译命令所需的文件也复制到该文件夹中并重试。 DLL编译成功;
但是,当我尝试使用 Excel(启用宏)工作簿中的 DLL 时,出现错误 DLL 未找到。当尝试在 Excel 中引用 DLL 时(通过“工具”->“引用”->“浏览”->“选择Dll”),它告诉我它无法添加 DLL。
使用 DependencyWalker 检查 DLL 时,出现以下错误:
Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
您对如何解决这个问题有什么想法吗?
多谢...
Update
当我尝试使用文档中所述的 C++ 编译库时,我最终收到以下错误消息:
PS C:\Users\dev\programming\excel_haskell_binding> ghc -o tester.exe .\Tester.cpp .\include\Adder.dll.a
C:\Users\dev\AppData\Local\Temp\ghc4088_0\ghc4088_0.o:ghc4088_0.c:(.text+0x0): multiple definition of `main'
Tester.o:Tester.cpp:(.text+0x0): first defined here
C:\Users\dev\AppData\Local\Temp\ghc4088_0\ghc4088_0.o:ghc4088_0.c:(.text+0x4f): undefined reference to `ZCMain_main_closure'
c:/ghc/ghc-7.6.1/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.6.3/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\dev\AppData\Local\Temp\ghc4088_0\ghc4088_0.o: bad reloc address 0x0 in section `.pdata'
collect2: ld returned 1 exit status
Update 2
我也在尝试不同的方法;看到这个问题GHC 编译 DLL 以在 VBA 中使用 https://stackoverflow.com/questions/52734002/ghc-compile-dll-for-use-in-vba