dshu1235 2018-08-18 03:20
浏览 352

调用cgo宏函数

I have a cgo program:

package main

//#define sum(a,b) (a)+(b)
import "C"

func main() {
        print(C.sum(1,2))
}

It should be very straight forward and print 3. But compilation failed:

could not determine kind of name for C.sum

As limited documentation I found with cgo and after some test, cgo works with macro constants, but how can I get it work with macro functions/arguments?

  • 写回答

1条回答 默认 最新

  • dongyi2159 2018-09-08 20:48
    关注

    Simple, you just need a wrapper:

    //#define SUM(a,b) (a)+(b)
    //int sum(int a, int b) {
    //  return SUM(a,b);
    //}
    import "C"
    
    func main() {
        print(C.sum(1, 2))
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱