How to specify toolchain if multiple are installed (e.g. glibc and musl)?

agolangf · 2017-04-15 20:00:13 · 628 次点击    
这是一个分享于 2017-04-15 20:00:13 的资源,其中的信息可能已经有所发展或是发生改变。

If a Linux host has gcc with both [g]libc-dev and musl-dev installed, how should the user signal to the go compiler which one to use, when producing glibc vs musl binaries?


评论:

Creshal:

CC=musl-gcc go build

mcandre:

Odd, go1.8.1 appears to ignore $CC, at least in OpenSuSE amd64.

I set $CC to musl-gcc, gcc, and no-such-gcc. All of these end up using /usr/bin/[g]cc, not sure which is called yet.

Some Go distributions behave differently. Alpine's go package has go build dynamically linking against musl, while Debian/Ubuntu's golang package has go build statically linking with the GNU/Linux kernel.

Even more confusing, Alpine's go build default coniguration can be overridden with the traditional go build --ldflags '-linkmode external -extldflags "-static"', in order to produce completely static binaries that bundle musl. While Debian/Ubuntu's go build can't easily disable static linking, at least not with flags I've played with.


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

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