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

x/mobile/cmd/gomobile: CGO_CFLAGS is overwritten during go bind -target=ios #12929

Open
hsinhoyeh opened this issue Oct 14, 2015 · 3 comments

Comments

@hsinhoyeh
Copy link

commented Oct 14, 2015

hi,
I faced an issue when I run gomobile bind with CGO_CFLAGS and CGO_LDFLAGS like

CGO_CFLAGS="-I/usr/local/include" \
CGO_LDFLAGS="-L/usr/local/lib" gomobile build -target=ios -v

but output told me that there a header file not found.
It turns out when we build ios, the CGO_CFLAGS and CGO_LDFLAGS are overwritten.
https://github.com/golang/mobile/blob/master/cmd/gomobile/env.go#L132

I have a way to workaround this:

index 5458bc2..00cb78c 100644
--- a/cmd/gomobile/env.go
+++ b/cmd/gomobile/env.go
@@ -119,8 +119,8 @@ func envInit() (err error) {
                "GOARM=7",
                "CC=" + clang,
                "CXX=" + clang,
-               "CGO_CFLAGS=" + cflags + " -arch " + archClang("arm"),
-               "CGO_LDFLAGS=" + cflags + " -arch " + archClang("arm"),
+               "CGO_CFLAGS=" + os.Getenv("CGO_CFLAGS") + " " + cflags + " -arch " + archClang("arm"),
+               "CGO_LDFLAGS=" + os.Getenv("CGO_LDFLAGS") + " " + cflags + " -arch " + archClang("arm"),
                "CGO_ENABLED=1",
        }
        darwinArm64Env = []string{
@@ -128,8 +128,8 @@ func envInit() (err error) {
                "GOARCH=arm64",
                "CC=" + clang,
                "CXX=" + clang,
-               "CGO_CFLAGS=" + cflags + " -arch " + archClang("arm64"),
-               "CGO_LDFLAGS=" + cflags + " -arch " + archClang("arm64"),
+               "CGO_CFLAGS=" + os.Getenv("CGO_CFLAGS") + " " + cflags + " -arch " + archClang("arm64"),
+               "CGO_LDFLAGS=" + os.Getenv("CGO_LDFLAGS") + " " + cflags + " -arch " + archClang("arm64"),
                "CGO_ENABLED=1",
        }

@@ -142,8 +142,8 @@ func envInit() (err error) {
                "GOARCH=386",
                "CC=" + clang,
                "CXX=" + clang,
-               "CGO_CFLAGS=" + cflags + " -mios-simulator-version-min=6.1 -arch " + archClang("386"),
-               "CGO_LDFLAGS=" + cflags + " -mios-simulator-version-min=6.1 -arch " + archClang("386"),
+               "CGO_CFLAGS=" + os.Getenv("CGO_CFLAGS") + " " + cflags + " -mios-simulator-version-min=6.1 -arch " + archClang("386"),
+               "CGO_LDFLAGS=" + os.Getenv("CGO_LDFLAGS") + " " + cflags + " -mios-simulator-version-min=6.1 -arch " + archClang("386"),
                "CGO_ENABLED=1",
        }
        darwinAmd64Env = []string{

let me know if you think this is an issue.

@crawshaw

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2015

It would be nice to be able to set these flags when using gomobile. It's an odd middle-ground however: we deliberately ignore some variables like GOOS, GOARCH, CC, and CXX, but we will use the flags variables? And we will apply the same CC flags to different compilers?

@rakyll rakyll changed the title x/mobile/cmd/gomobile: CGO_CFLAGS is overwritten during go bind -targe=ios x/mobile/cmd/gomobile: CGO_CFLAGS is overwritten during go bind -target=ios Oct 15, 2015

@rakyll rakyll added this to the Unreleased milestone Oct 15, 2015

@hsinhoyeh

This comment has been minimized.

Copy link
Author

commented Oct 16, 2015

I think it is better to have a flag variable to determine whether we want to inherit CFO_CFLAGS and CGO_LDFLAGS from env. It should be caller's call to deal with different compilers.
how do you think?

@gopherbot gopherbot added the mobile label Jul 20, 2017

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Mar 16, 2018

With https://go-review.googlesource.com/99316 in it is now possible to generate complete bindings with the gobind tool, skip gomobile and build the JNI lbraries manually with CC=... CXX=... CGO_ENABLED=1 GOOS=android GOARCH=... go build -buildmode=c-shared.
(With pending https://go-review.googlesource.com/c/mobile/+/99875 gomobile will change to use standalone toolchains, and build exactly as above)
Does that solution help you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.