为什么Go在dll中找不到指定的过程?
我有一个为 Windows x86 编译的 my.dll
库(操作系统是 Windows 7 x64;但我使用的是 Go x86 二进制文件 - 带有 LiteIDE - 并且 C# 代码也明确编译为 x86建筑学)。我在 C# 中使用它并且它有效:
[DllImport("my.dll", EntryPoint = "my_function")]
public static extern double my_function(double x);
但是当我尝试通过 Go 使用它时(这里我只是想找到它):
var (
dllMine = syscall.NewLazyDLL("my.dll")
my_function = dllMine.NewProc("my_function")
)
func main() {
err := my_function.Find()
if err != nil {
fmt.Println(err)
return
}
//...
}
它说 无法在 my.dll 中找到 my_function 过程:找不到指定的过程。
。 my.dll
文件与生成的 .exe
文件位于同一目录中。入口点名称 ("my_function"
) 确实存在,因为它在 C# 中导入时工作正常,并且不会显示 Failed to load my.dll: The specified module could not be found。
。
实际部分:我尝试调用的库是 swedll32.dll
,它是 Swiss Ephemeris 的核心库(可以下载 here - GNU)并且只是为了测试这个场景的函数被调用的是 swe_julday
;使用此签名重现错误:
double swe_julday(
int year, int month, int day, double hour,
int gregflag); /* Gregorian calendar: 1, Julian calendar: 0 */
另一件事是我的 GOROOT
环境参数实际上是一个 NTFS 连接点(因此我可以在 x86 和 x64 版本之间切换)——但我认为它不相关,因为输出 . exe
应用程序的生成没有任何问题(只是为了忏悔我所有的罪过!)。
最佳答案
我已经从http://www.astro.com/ftp/swisseph/sweph.zip下载了你的dll查看 swe_julday 函数是否在那里:
C:\foo>dumpbin /exports swedll32.dll | find "swe_julday"
74 49 0000C440 _swe_julday@24
75 4A 0000D4A0 _swe_julday_d@24
我在那里没有看到 swe_julday 函数。相反,我看到了 _swe_julday@24 函数。因此,如果我将您的程序更改为:
C:\foo>type foo.go
package main
import (
"syscall"
"fmt"
)
var (
dllMine = syscall.NewLazyDLL("swedll32.dll")
my_function = dllMine.NewProc("_swe_julday@24")
)
func main() {
err := my_function.Find()
if err != nil {
fmt.Println(err)
return
}
//...
}
它运行没有任何错误:
C:\foo>go run foo.go
C:\foo>
关于windows - Go 无法在 DLL 中查找过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26886571/