Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: invalid flag in #cgo CFLAGS: -F #51008

Closed
zyxkad opened this issue Feb 4, 2022 · 9 comments
Closed

cmd/go: invalid flag in #cgo CFLAGS: -F #51008

zyxkad opened this issue Feb 4, 2022 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@zyxkad
Copy link

zyxkad commented Feb 4, 2022

What version of Go are you using (go version)?

$ go version
go version go1.17.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="**"
GOCACHE="**"
GOENV="**"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="**"
GONOPROXY="yes"
GONOSUMDB=""
GOOS="darwin"
GOPATH="**"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2 -std=c17"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2 -std=c++17"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fh/sxp5v53x66j5_p6_9rxtx6b80000gp/T/go-build2886836689=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package my_cgo

//#cgo CFLAGS: -F /usr/local/my_framework/lib -framework MyFramework
//#cgo LDFLAGS: -F /usr/local/my_framework/lib -framework MyFramework
//
//#include <MyFramework/somefile.h>
import "C"

What did you expect to see?

Success

What did you see instead?

go build xxx/xxx/xxx: invalid flag in #cgo CFLAGS: -F
[Finished in 458ms with exit code 1]


The option -F is actually in clang

$ clang --help | grep '\-F'
 -F <value>              Add directory to framework include search path
$ clang++ --help | grep '\-F'
 -F <value>              Add directory to framework include search path
@ianlancetaylor ianlancetaylor changed the title go/cgo: CFLAGS: don't allow -F option with clang cmd/go: invalid flag in #cgo CFLAGS: -F Feb 4, 2022
@ianlancetaylor
Copy link
Contributor

Was that the complete error message? With Go 1.17 the error message should have mentioned https://golang.org/s/invalidflag, which explains how you can work around the problem.

@zyxkad
Copy link
Author

zyxkad commented Feb 4, 2022

Yes that's all, but it don't tell me https://golang.org/s/invalidflag

@zyxkad
Copy link
Author

zyxkad commented Feb 4, 2022

I was running go test -v ${file}, and I got the error

@zyxkad
Copy link
Author

zyxkad commented Feb 4, 2022

I was trying CGO_CFLAGS_ALLOW, but it dosen't work

$ go env -w CGO_CFLAGS_ALLOW="-F"; echo $?
0
$ go env CGO_CFLAGS_ALLOW
[[GOT EMPTY]]

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 4, 2022
@toothrot toothrot added this to the Backlog milestone Feb 4, 2022
@bcmills
Copy link
Contributor

bcmills commented Feb 4, 2022

@zyxkad, do you have CGO_CFLAGS_ALLOW explicitly set in your process environment? A value in the environment always overrides the value in the go.env file.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 4, 2022
@ianlancetaylor
Copy link
Contributor

From the code it looks like -F/usr/local/my_framework/lib will work without any environment variable setting, but we didn't consider the case of -F /usr/local/my_framework/lib (with a space after the -F).

@gopherbot
Copy link

Change https://golang.org/cl/383217 mentions this issue: cmd/go: accept "-F dir" in compiler flags

@zyxkad
Copy link
Author

zyxkad commented Feb 4, 2022

@zyxkad, do you have CGO_CFLAGS_ALLOW explicitly set in your process environment? A value in the environment always overrides the value in the go.env file.

No, I wasn't, I also try export CGO_CFLAGS_ALLOW="-F"
but it always return to me nothing

@zyxkad
Copy link
Author

zyxkad commented Feb 4, 2022

From the code it looks like -F/usr/local/my_framework/lib will work without any environment variable setting, but we didn't consider the case of -F /usr/local/my_framework/lib (with a space after the -F).

Yes, that's work for me, thanks

@golang golang locked and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants