https://github.com/zchee/go-tips
https://github.com/zchee/go-tips
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zchee/go-tips
- Owner: zchee
- License: bsd-3-clause
- Created: 2016-10-10T03:45:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-23T05:58:23.000Z (about 8 years ago)
- Last Synced: 2025-01-16T19:49:22.030Z (about 1 year ago)
- Size: 18.6 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go Tips
=======
multiple `-extldflags` arguments
--------------------------------
### Q:
`-extldflags` is must be including `-ldflags` build flag.
But if execute the `go build ...` command use some script(such as `Makefile`), sometimes failed go's `link` linker with below error.
```sh
flag provided but not defined: -fooflag'
```
build command is here.
```sh
go bulid -ldflags="-w -s -extldflags='-static -fooflag' example.com/john/doe"
```
However, will successful with `-extldflags=-static`.
### A:
In this case, go `link` linker will recognizes `link -fooflag -extldflags='-static`.
To be cleared, `link` passes flags to `extld` command(such as `ld`) `-static` only.
As in the [golang/go/issues/6234](https://github.com/golang/go/issues/6234) and [docker-library/golang/issues/152](https://github.com/docker-library/golang/issues/152), need
```sh
# -d disable dynamic executable
# -s disable symbol table
# -w disable DWARF generation
go build -ldflags="-d -s -w '-extldflags=-static'" example.com/john/doe
```
Actually, We must be bracketed to `-extldflags=...` by a comma(`'`).
After that, will passes all flags to C linker. Try and check with add `-v` to `-extldflags`.
Available`#cgo` magic comment
-----------------------------
Go version: `devel +334cbe3 Sun Oct 9 22:50:12 2016 +0000`
defined in `$GOROOT/src/go/build/build.go.saveCgo()` switch cases, available
```sh
CFLAGS
CPPFLAGS
CXXFLAGS
FFLAGS
LDFLAGS
pkg-config
```