Invalid flag in #cgo LDFLAGS

Trying to compile some static libraries into Go application.

Some of libraries are not called directly by Go application; instead, they are registered into a common library through GCC constructor function. But I those libraries are not compiled into the final Go binary. So I added -Wl,–whole-archive to make libraries not dropped by the linker. However, I got this error:

“go build _/some/example: invalid flag in #cgo LDFLAGS: -Wl,–whole-archive”

I’ve tried Go 1.6, 1.7, 1.8, 1.10.1, 1.10.4. Anyone can help on this?

The cmd used for compile:
$ go build -x -v --ldflags ‘-linkmode external -extldflags “-static”’ -a

The go application:

package main

// #cgo CFLAGS: -I.
// #cgo LDFLAGS: -L. -Wl,–whole-archive -lhello -Wl,–no-whole-archive
// #include <hello.h>

Thanks,
Jianfeng

I find the answer here: https://github.com/golang/go/wiki/InvalidFlag.

This is what I’ve done before go build:
$ export CGO_LDFLAGS_ALLOW=".*"

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.