建立一个DLL与围棋1.7

问题描述:

是否有建立在Windows下对围棋V1.7一个dll的方法吗?建立一个DLL与围棋1.7

我尝试了经典

go build -buildmode=shared main.go 

,但得到

-buildmode =共享不支持Windows/AMD64

更新 好吧,我有我的回答。对于那些有兴趣谁: https://groups.google.com/forum/#!topic/golang-dev/ckFZAZbnjzU

+0

'-buildmode = shared'是一个围棋共享库,这会不会让一个DLL反正。你最有可能正在寻找'buildmode = C-shared',虽然尚未制定对窗口着呢,你可以按照[问题#11058(https://golang.org/issue/11058) – JimB

go build -buildmode=c-archive github.com/user/ExportHello 

====>将建立ExportHello.aExportHello.h

以建于ExportHello.a和再出口的功能Hello2.c

gcc -shared -pthread -o Hello2.dll Hello2.c ExportHello.a -lWinMM -lntdll -lWS2_32 

== ==>将生成Hello2.dll

有一个在github上项目,该项目展示了如何创建一个DLL的基础上,并感谢user7155193的答案。

基本上你使用GCC从golang生成的.a和.h文件构建DLL。

首先你要的是出口的函数(或更多)的简单围棋文件。

package main 

import "C" 
import "fmt" 

//export PrintBye 
func PrintBye() { 
    fmt.Println("From DLL: Bye!") 
} 

func main() { 
    // Need a main function to make CGO compile package as C shared library 
} 

与编译:

go build -buildmode=c-archive exportgo.go 

然后你犯了一个C程序(goDLL.c)将在.H链接及以上

#include <stdio.h> 
#include "exportgo.h" 

// force gcc to link in go runtime (may be a better solution than this) 
void dummy() { 
    PrintBye(); 
} 

int main() { 

} 

编译生成.a文件/链接DLL与GCC:

gcc -shared -pthread -o goDLL.dll goDLL.c exportgo.a -lWinMM -lntdll -lWS2_32 

的goDLL.dll然后可以被装载到另一个C程序中,一个FreePascal的/拉扎勒斯程序,或者你选择的程序。

完整的代码与加载DLL中的拉撒路/ FPC项目是在这里: https://github.com/z505/goDLL