Is there a way to tell the compiler not to use some code if compiling to an arch?

xuanbao · 2017-05-16 11:00:05 · 410 次点击    
这是一个分享于 2017-05-16 11:00:05 的资源,其中的信息可能已经有所发展或是发生改变。

I have code in my project that will only work compiling it for windows, I am wanting to know if there is something i can put in code wise that will tell the compiler to ignore these functions and imports if compiling for not windows systems. So i don't have to edit the files everytime i compile for another system.


评论:

brianketelsen:

yes! The simplest thing to do is add your windows specific code to a file called mystuff_windows.go see this great article: https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool

SaturnsVoid:

Thanks will look into this!

RandNho:

Some people do horrible stuff with runtime os detection.
That's wrong and bad. Conditional compilation, as was said, is the way.

dchapes:

They're called build constraints.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

410 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传