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

Open
hsinhoyeh opened this issue Oct 15, 2015 · 6 comments

Comments

@hsinhoyeh
Copy link

commented Oct 15, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2015

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented Oct 16, 2015

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Oct 29, 2015

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

@gopherbot gopherbot added the mobile label Jul 20, 2017

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Mar 16, 2018

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

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