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:

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?

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

1条回答 默认 最新

  • dpyic24480
    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 explains. Works great.

    点赞 评论