dpzjl68484 2016-01-21 19:59
浏览 424
已采纳

Go build shared-c不输出头文件

I am trying to test build a shared C lib in GoLang, and the output does not create a header file (.h)

test.go:

package main

import "C"
import "fmt"

func ExportedFun(s string) {
    fmt.Printf("C gave us %s string", s)
}

func main() {}

and the command I run is:

go build -buildmode=c-shared -o test.so test.go

I get the .so file but no header file. Is there something I am missing?

  • 写回答

1条回答 默认 最新

  • dpda53918 2016-01-21 20:25
    关注

    From the go command documentation:

    The only callable symbols will be those functions exported using a cgo //export comment.

    Th syntax for exporting a function via cgo can be found in the cgo documentation

    Go functions can be exported for use by C code in the following way:

    //export MyFunction
    func MyFunction(arg1, arg2 int, arg3 string) int64 {...}
    
    //export MyFunction2
    func MyFunction2(arg1, arg2 int, arg3 string) (int64, *C.char) {...}
    

    Marking your function as exported will generate the header.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致