无法确定 C.free 的名称类型

我正在尝试在我的Golang应用程序中使用。我的代码如下:C.free


package main


import (

    "fmt"

    "unsafe"

)


// #include <stdlib.h>


import (

    "C"

)



//export FreeMemory

func 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


谢谢


喵喔喔
浏览 134回答 1
1回答

牛魔王的故事

如果导入“C”紧跟在注释之前,则在编译包的 C 部分时,该注释(称为前导码)将用作标头。例如:// #include <stdio.h>&nbsp;// #include <errno.h>&nbsp;import "C"package mainimport "unsafe"// #include <stdlib.h>import "C"//export FreeMemoryfunc FreeMemory(pointer *int64) {&nbsp; &nbsp; C.free(unsafe.Pointer(pointer))}func main() {}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go