How to cross-compile libc variants like musl?

xuanbao · · 451 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Most Linux binaries implicitly link to GNU libc, however recent Linux flavors like Alpine actually include musl, rather than libc.</p> <p>What&#39;s the best way to setup a Go project to build one binary for GNU libc, and another binary for musl libc, so that no matter which Linux flavor the user has, the corresponding binary can be easily published online?</p> <p>Go&#39;s toolchain includes out-of-the-box support for a wide variety of systems, however there does not appear to be much support for musl yet. This leads me to believe that a separate build bot is necessary (compiling for GNU libc on a GNU/Linux build host, compiling for musl libc on an Alpine build host). But I would prefer to build these two variant binaries from the very same developer machine if possible.</p> <p>What do you think?</p> <hr/>**评论:**<br/><br/>4ad: <pre><p>In most cases you can avoid linking with libc on Linux if you don&#39;t need cgo.</p> <p>You can also statically link with musl, but note that musl lacks features that people might want to use non-pure Go in the first place. For example, musl does&#39;t support arbitrary name resolvers, e.g. no LDAP support; it only supports DNS, just like the pure Go net package.</p> <p>On the other hand musl does support os/user.</p></pre>pierrrre: <pre><p>build your binary from the docker image golang:1.8.1-alpine</p></pre>

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

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