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.

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

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突