Golang:调用Windows DLL函数 [英] Golang: call Windows DLL functions

查看:614
本文介绍了Golang:调用Windows DLL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Go应用程序,可以调用Windows DLL。该DLL用MSVC编写,并使用__declspec(dllexport)进行外部C导出。

I am writing a Go app that calls into a Windows DLL. The DLL was written with MSVC and has extern "C" exports using __declspec(dllexport).

Go应用程序的顶部如下所示:

The top of my Go app is as follows:

//#cgo CFLAGS: -IC:/Repos/Module/include
//#cgo LDFLAGS: -L. C:/Repos/Module/go/bin/MyModule.dll
//#include <MyModule.h>
import "C"

我从模块调用函数,如下所示:

I'm calling functions from the module like so:

nRet := C.moduleImpl_len()

问题是,当我尝试运行此应用程序时,出现以下错误:

The problem is that when I try to run this app, I get the following error:

C:\Users\MINDO~1\AppData\Local\Temp\go-build836751819\mod\modimpl\_obj\modimpl.cgo2.o: In function `_cgo_e2aaf076ab69_Cfunc_moduleImpl_len':
C:/Repos/Module/go/src/mod/modimpl/modimpl.go:90: undefined reference to `moduleImpl_len'

我使用DUMPBIN查看了DLL导出的符号,并且它精确地显示了moduleImpl_len作为导出的符号。这也是MyModule.h中定义的符号。

I looked at the DLL exported symbols with DUMPBIN and it showed exactly "moduleImpl_len" as the exported symbol. This is also the symbol as defined in MyModule.h.

有关如何让符号链接而不必进入系统调用路径的任何建议?

Any suggestions on how I can get the symbols to link without having to go the syscall route?

推荐答案

如果你想链接到dll,你需要/想要LDFLAGS中的-lMyModule? https://stackoverflow.com/a/15853231/32453

If you're trying to link against the dll you need/want "-lMyModule" in the LDFLAGS? https://stackoverflow.com/a/15853231/32453

这篇关于Golang:调用Windows DLL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆