duanaoyuan7202 2016-03-01 09:42
浏览 268

在CGO中定义变量

I want, at build time, to define a string variable in cgo. None of the following approaches works.

  1. #cgo CFLAGS: -DLOG="common"  
    

    'common' undeclared (first use in this function)

  2. #cgo CFLAGS: -DLOG=common
    

    'common' undeclared (first use in this function)

  3. #cgo CFLAGS: -DLOG=\"common\"
    

    malformed #cgo argument: -DLOG="common"

  • 写回答

2条回答 默认 最新

  • duanke1286 2016-05-22 19:38
    关注

    It appears this is not possible as cgo does some mangling/parsing -- can you get away with just a normal #define LOG "common" (i.e. not use the CGO special flags).

    Or failing that You can invoke go run/go build like this: CGO_CFLAGS='-DLOG="common"' go run so.go

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料