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: c++ library on mac #12948

Closed
hsinhoyeh opened this issue Oct 15, 2015 · 7 comments
Closed

x/mobile/cmd/gomobile: c++ library on mac #12948

hsinhoyeh opened this issue Oct 15, 2015 · 7 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@hsinhoyeh
Copy link

hi,
I am working on build c/c++ library with cgo into ios platform (by gomobile)
when I run go bind -target=ios, you actually build three environments:
https://github.com/golang/mobile/blob/master/cmd/gomobile/bind_iosapp.go#L49

for _, env := range [][]string{darwinArmEnv, darwinArm64Env, darwinAmd64Env} {
        arch := archClang(getenv(env, "GOARCH"))
        path, err := goIOSBindArchive(name, mainFile, env)
        if err != nil {
            return fmt.Errorf("darwin-%s: %v", arch, err)
        }
        cmd.Args = append(cmd.Args, "-arch", arch, path)
    }

and it turns out that "by default" darwinArmEnv and darwinArm64Env use libc++ library, while darwinAmd64Env use libstdc++.

the following workaround works for me:

diff --git a/cmd/gomobile/env.go b/cmd/gomobile/env.go
index dcb79eb..98371f4 100644
--- a/cmd/gomobile/env.go
+++ b/cmd/gomobile/env.go
@@ -154,8 +154,8 @@ func envInit() (err error) {
                "GOARCH=amd64",
                "CC=" + clang,
                "CXX=" + clang,
-               "CGO_LDFLAGS=" + cflags + " -mios-simulator-version-min=6.1 -arch x86_64",
+               "CGO_LDFLAGS=" + cflags + " -mios-simulator-version-min=6.1 -arch x86_64 -stdlib=libc++",
                "CGO_ENABLED=1",
        }

I think it is better to allow CXXFLAGS can be passed when build.

@crawshaw
Copy link
Member

Thanks, that's surprising. It's probably worth setting that by default. Would you like to send a CL, or rather I do it?

@rakyll
Copy link
Contributor

rakyll commented Oct 15, 2015

I am wondering whether there is any advantage of keep using the system default, libstdc++, given the fact that libc++ and libcstd++ are not ABI compatible.

@rakyll rakyll added this to the Unreleased milestone Oct 15, 2015
@hsinhoyeh
Copy link
Author

if we keep libc++ as default, we need to document somewhere which tells that we always need to use CXXFLAGS="-stdlib=libc++" to build c/c++ project before link to gomobile.

@crawshaw I will send a CL and also think how to add a unittest. Is it ok to add a test by linking cgo and gomobile? In my case, I use https://github.com/jmhodges/levigo and https://github.com/google/leveldb

@hyangah
Copy link
Contributor

hyangah commented Oct 16, 2015

@hsinhoyeh adding test sounds great. Just don't depend on 3rd party repositories; instead come up with minimal cgo examples.

@rakyll rakyll self-assigned this Oct 29, 2015
@gopherbot
Copy link

CL https://golang.org/cl/16466 mentions this issue.

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
@eliasnaur
Copy link
Contributor

Is this a problem? Perhaps the default std. c++ runtime has changed with newer iOS SDKs.

@hyangah
Copy link
Contributor

hyangah commented Apr 6, 2022

Closing. This is obsolete.

@hyangah hyangah closed this as completed Apr 6, 2022
@rsc rsc unassigned rakyll Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

6 participants