我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

调用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?

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))
}

近期文章

  • 微服务消息传递
  • Docker容器未找到所需的依赖项
  • 在Go中计算逆对数范数
  • 在安卓程序里 如何从EditText里获取插入的图片
  • 在Golang中获取数据库连接的连接字符串
  • 从Go脚本连续执行tshark
  • Redigo ScanStruct错误与time.Time
  • 将项目插入表中的AWS DynamoDB Golang问题
  • Golang ParseFloat在示例中不准确
  • 我无法让golang识别带有参数的get请求
  • Gorilla Websocket手动关闭客户端连接
  • 努力用gogradle编译go项目
  • 模糊匹配坐标列表(Golang)
  • 使用golang服务静态文件
  • go-pg“属于”同一表的2个字段
  • 在Go中关闭自动进纸通道
  • 将protobuf枚举消息发送到grpc服务器
  • mgo是否具有根据查询结果对每个文档的特定“切片”字段进行排序的功能?
  • PostgreSQL:从代码执行查询时,“ pq:关系列不存在”,但在控制台中工作正常
  • PostgreSQL-语法错误在“,”附近

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华