我正在嘗試在我的Golang應用程序中使用。我的代碼如下:C.freepackage mainimport ( "fmt" "unsafe")// #include <stdlib.h>import ( "C")//export FreeMemoryfunc FreeMemory(pointer *int64) { C.free(unsafe.Pointer(pointer))}我做了一些搜索,我知道錯誤是因為我沒有包括在內,但我有。stdlib.h這是我的構建命令:。我在構建后得到的錯誤是:go build --buildmode=c-shared -o main.dllcould not determine kind of name for C.free我的操作系統是視窗 10謝謝
1 回答

牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
如果導入“C”緊跟在注釋之前,則在編譯包的 C 部分時,該注釋(稱為前導碼)將用作標頭。例如:
// #include <stdio.h>
// #include <errno.h>
import "C"
package main
import "unsafe"
// #include <stdlib.h>
import "C"
//export FreeMemory
func FreeMemory(pointer *int64) {
C.free(unsafe.Pointer(pointer))
}
func main() {}
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消