rthornton128 / goncurses

NCurses Library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pkgconfig problem

Zaryob opened this issue · comments

go get github.com/rthornton128/goncurses
github.com/rthornton128/goncurses
go build github.com/rthornton128/goncurses: invalid flag in pkg-config --libs: -Wl,-O2
go version
go version go1.14.10 linux/amd64

I'm running in opensuse. and goncurses cannot compiled due to belown issue. I controlled all ncurses installation and other stuff. ncurses C applications can compiled with same ncurses.

ncursesw6-config --cflags --libs
-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/ncursesw
-Wl,-O2 -Wl,-Bsymbolic-functions -Wl,--as-needed -lncursesw -ltinfo

This is due to a limitation in CGO not accepting the flags.

For security reasons, only a limited set of flags are allowed, notably -D, -U, -I, and -l. To allow additional flags, set CGO_CFLAGS_ALLOW to a regular expression matching the new flags. To disallow flags that would otherwise be allowed, set CGO_CFLAGS_DISALLOW to a regular expression matching arguments that must be disallowed. In both cases the regular expression must match a full argument: to allow -mfoo=bar, use CGO_CFLAGS_ALLOW='-mfoo.*', not just CGO_CFLAGS_ALLOW='-mfoo'. Similarly named variables control the allowed CPPFLAGS, CXXFLAGS, FFLAGS, and LDFLAGS.

See the go docs for details.

I'm not sure there's anything can can be done for this package. Possibly the #cgo directives can be used to this affect.

Related issue: #50

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.

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

with trying these. I will re-comment.

@Zaryob note that there is an asterisk after the dot in the first two lines.
As rthornton mentioned, the CGO_*FLAGS_ALLOW are basically filters for which arguments are passed to the C compiler used by CGo. The form of these variables is a regular expression of patterns, .* in RegEx means anything.

Keep in mind that it's a workaround and by no means a production-ready fix.
Technically, you'd need to check which tool in the chain needs which flags and allow them separately.
.* also allows unwanted or potentially malicious compiler flags to be passed through CGO to gcc.