Qt: compilation failed with recent go: invalid flag in #cgo CFLAGS: -pipe

Created on 12 Feb 2018  ·  7Comments  ·  Source: therecipe/qt

go version go1.9.4 linux/amd64

since 1.9.4 cgo args are whitelisted, some are missing to compile the qt bindings
-fno-plt -isystem -Wl,-O1 -pipe ...
See https://github.com/golang/go/issues/23672
relates to https://github.com/golang/go/issues/23749

temp fix:

export CGO_CXXFLAGS_ALLOW=".*" 
export CGO_LDFLAGS_ALLOW=".*" 
export CGO_CFLAGS_ALLOW=".*" 
$GOPATH/bin/qtsetup

All 7 comments

Is there any temp fix for windows?

CGO_CXXFLAGS_ALLOW, CGO_LDFLAGS_ALLOW, and CGO_CFLAGS_ALLOW dont seem to work as env variables.

From what I can tell qtdeploy uses a limited set of environment variables when it does the final build. These three flags aren't included.
I changed github.com\therecipe\qt\internal\cmd\cmd.go:

        env = map[string]string{
            "PATH":   os.Getenv("PATH"),
            "GOPATH": utils.GOPATH(),
            "GOROOT": runtime.GOROOT(),

            "TMP":  os.Getenv("TMP"),
            "TEMP": os.Getenv("TEMP"),

            "GOOS":   "windows",
            "GOARCH": "386",

            "CGO_ENABLED": "1",
            "CGO_CFLAGS_ALLOW": ".*",
            "CGO_CXXFLAGS_ALLOW": ".*",
            "CGO_LDFLAGS_ALLOW": ".*",
        }

Notice the last three lines. Rebuild qtdeploy

invalid flag in #cgo CFLAGS:  -fno-keep-inline-dllexport

google找了一圈找到这,加上这条信息方便后来者搜索到这个错误原因
我是换1.9.3版本了。

上面给的环境变量在msys2上不好使。

Hey

This should be fixed now with: https://github.com/therecipe/qt/commit/299f21022aa217faace4fae811ddd2ede4e35c9d

They sneaked this breaking change in after I tested the Go 1.10 beta ...

They sneaked this breaking change in after I tested the Go 1.10 beta ...

@therecipe in OS X with go 1.10 I still got this error

$ go install -v ./...
github.com/therecipe/qt/webview
go build github.com/therecipe/qt/webview: invalid flag in #cgo CFLAGS: -arch
github.com/therecipe/qt/core
go build github.com/therecipe/qt/core: invalid flag in #cgo CFLAGS: -arch

Is there anything else we should do?

@favadi

You will still need to export:

CGO_CXXFLAGS_ALLOW=".*" 
CGO_LDFLAGS_ALLOW=".*" 
CGO_CFLAGS_ALLOW=".*" 

if you use "go install" or "go build".

I just "fixed" this in qtdeploy, but there is nothing I can do about the go tool.
Maybe I will collect a list of compiler flags, so that they can be whitelisted in the go tool.
But there are 100's of them ...

Will close this now, since it should work with the latest version of this binding (0e3cd9505298e99148fa12b6ffd207364155a9d7) and an somewhat recent version of go (1.11.2) without the need to whitelist CGO flags.

Some older go versions (1.10.x) might probably still suffer from this though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

quantonganh picture quantonganh  ·  6Comments

joeblew99 picture joeblew99  ·  7Comments

adneg picture adneg  ·  6Comments

LimEJET picture LimEJET  ·  6Comments

tapir picture tapir  ·  5Comments