dongsonglian7303
2019-07-19 23:50
浏览 85
已采纳

Windows DLL文件的正确的构建模式是什么?

These two steps:

gcc -c main.c
gcc -o a.exe main.o MyThing.dll

Work great to make windows exe that can call methods inside MyThing.dll. Note gcc main.c without the -c would give error like:

undefined reference to MyThing_method

But when trying to get this same system working in a Golang program using cgo I get same undefined reference errors like I did with gcc without the -c. I've read:

https://github.com/golang/go/wiki/WindowsDLLs

And would love to try and use syscall.NewLazyDLL but my issue is my foo.go file is calling C.SomeMethod() and inside that method it makes calls to the methods inside the DLL. So it seems I need a way to

go build -buildmode=c-share -o MyThing.dll

But I can't seem to get the right sequence. Am I right that if I can do this in the simple C program, there must be a way to do this from Golang?

图片转代码服务由CSDN问答提供 功能建议

这两个步骤:

  gcc -c main.c  
gcc -o a.exe main.o MyThing.dll 
   
 
 

可以很好地使Windows exe可以调用MyThing.dll中的方法。 注意不带-c的gcc main.c会给出如下错误:

未定义对MyThing_method的引用

为了使这个相同的系统在使用cgo的Golang程序中工作,我得到了相同的未定义参考错误,就像我使用不带-c的gcc一样。 我读过:

https:// github。 com / golang / go / wiki / WindowsDLLs

并且很想尝试使用 syscall.NewLazyDLL ,但是我的问题是我的foo.go文件 正在调用C.SomeMethod(),并且在该方法内部调用DLL中的方法。 所以看来我需要一种方法

去构建-buildmode = c-share -o MyThing.dll

但是我似乎找不到正确的顺序。 我对吗,如果我可以在简单的C程序中做到这一点,那么必须有一种从Golang做到这一点的方法吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpyic24480 2019-07-21 22:00
    已采纳

    I ended up just getting rid of this extra c file and calling the methods I needed from Go like https://github.com/golang/go/wiki/WindowsDLLs explains. Works great.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题