DLL을 만드는 법을 보여준 github 프로젝트, user7155193의 답변 덕택에.
기본적으로 GCC를 사용하여 생성 된 golang .a 및 .h 파일에서 DLL을 빌드합니다.
먼저 함수 (또는 그 이상)를 내보내는 간단한 Go 파일을 만듭니다.
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
당신이 .H에 연결하는 C 프로그램 (goDLL.c을)하고 운영자와 파일
#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() {
}
컴파일 위에 생성/GCC와 DLL을 연결하십시오 :
그런 다음 goDLL.dll을 다른 C 프로그램, freepascal/lazarus 프로그램 또는 선택한 프로그램에로드 할 수 있습니다.
DLL을로드하는 나사로/FPC 프로젝트에 전체 코드는 여기에 있습니다 : https://github.com/z505/goDLL
'-buildmode = shared' 어쨌든 DLL을하지 것이라고 이동 공유 라이브러리입니다. 당신은 아마도'buildmode = c-shared'를 찾고 있었을 것입니다. 아직 그 창문은 아직 작동하지 않았고, [issue # 11058] (https://golang.org/issue/11058)을 따라갈 수 있습니다. – JimB