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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献