如何告诉cgo不要编译一个文件?

huangapple go评论111阅读模式
英文:

how do I tell cgo not to compile a file?

问题

对于一个普通的Go文件,我会这样写:

  1. // +build !windows

然而,cgo将其解释为要编译的C代码。

那么我应该怎么做呢?

英文:

for a regular go file I say

  1. // +build !windows

however cgo interprets this as c code to get compiled

So what do I have to do?

答案1

得分: 7

构建约束必须出现在包声明之前。

错误的写法

  1. package mypackage
  2. // +build !windows
  3. // #include <header.h>
  4. //
  5. // ...
  6. import "C"

正确的写法

  1. // +build !windows
  2. package mypackage
  3. // #include <header.h>
  4. //
  5. // ...
  6. import "C"
英文:

The build constraint must appear before your package declaration.

Incorrect

  1. package mypackage
  2. // +build !windows
  3. // #include <header.h>
  4. //
  5. // ...
  6. import "C"

Correct

  1. // +build !windows
  2. package mypackage
  3. // #include <header.h>
  4. //
  5. // ...
  6. import "C"

huangapple
  • 本文由 发表于 2016年3月25日 06:11:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/36210871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定