<p>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.</p>
<hr/>**评论:**<br/><br/>brianketelsen: <pre><p>yes! The simplest thing to do is add your windows specific code to a file called mystuff_windows.go
see this great article: <a href="https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool">https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool</a></p></pre>SaturnsVoid: <pre><p>Thanks will look into this!</p></pre>RandNho: <pre><p>Some people do horrible stuff with runtime os detection.<br/>
That's wrong and bad. Conditional compilation, as was said, is the way.</p></pre>dchapes: <pre><p>They're called <a href="https://golang.org/pkg/go/build/#hdr-Build_Constraints" rel="nofollow">build constraints</a>.</p></pre>
Is there a way to tell the compiler not to use some code if compiling to an arch?
xuanbao · · 382 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传