rthornton128 / goncurses

NCurses Library for Go
Other
383 stars 51 forks source link

Build fails with "invalid flag in pkg-config" #50

Closed smadurange closed 4 years ago

smadurange commented 4 years ago

When I run go get github.com/rthornton128/goncurses, I get

go build github.com/rthornton128/goncurses: invalid flag in pkg-config --libs: -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now

I'm on Arch Linux.

rthornton128 commented 4 years ago

This is telling you that pkg-config is passing in flags the linker doesn't understand. This is likely something specific to Arch or how the package was installed.

I don't know enough to help you diagnose but I can say that -O1 seems misplaced as that's an optimization flag and should probably be emitted from --cflags, not --libs. I don't know what the -z related flags are.

amireldor commented 4 years ago

I think I have a similar problem, when I run this under an Ubuntu-based distro (20.04, Regolith) I get:

❯ go get github.com/rthornton128/goncurses
go build github.com/rthornton128/goncurses: invalid flag in pkg-config --libs: -Wl,-Bsymbolic-functions
n-hachi commented 4 years ago

@amireldor

If yo do the following settings, the problem may be solved.

$ export CGO_LDFLAGS_ALLOW="-Wl,-Bsymbolic-functions"
$ go get github.com/rthornton128/goncurses

The following is the reference URL. https://github.com/golang/go/wiki/InvalidFlag

scrouthtv commented 4 years ago

@n-hachi Doesn't work for me.

Like op, I'm running Linux archlinux 5.8.14-arch1-1 #1 SMP PREEMPT Wed, 07 Oct 2020 23:59:46 +0000 x86_64 GNU/Linux

Thanks for any help in advance.

rthornton128 commented 4 years ago

Further to what @n-hachi suggested, the "fix" is the *_ALLOW family of environment variables. See #55 for more details. Potentially, if it were to work, the #cgo directives might be used to allow the flags (though I suspect this won't work) but I'm reluctant to do that, as every package uses different flags and I'm reluctant to open it up to everything.

scrouthtv commented 3 years ago

If you don't want to dive into the depths of CGO compilation and that stuff here's a quick and insecure "workaround" using the fix mentioned above:

export CGO_CFLAGS_ALLOW=".*"
export CGO_LDFLAGS_ALLOW=".*"
go get github.com/rthornton128/goncurses
export CGO_CFLAGS_ALLOW=
export CGO_LDFLAGS_ALLOW=

It is important to reset the allowed flags again for security reasons.