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++ with SWIG #17343

Closed
vrabeux opened this issue Oct 5, 2016 · 8 comments
Closed

x/mobile/cmd/gomobile: c++ with SWIG #17343

vrabeux opened this issue Oct 5, 2016 · 8 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@vrabeux
Copy link

vrabeux commented Oct 5, 2016

  • go version 1.7
  • OSX

Hi,

I am trying to use gomobile to compile a small SDK (android + ios). This SDK contains both Go sources and C++ sources. C++ Go wrappers are generated with SWIG.

Sample project can be found here : https://github.com/vrabeux/testinggomobile

The command line :go build works but the gomobile bind -target=android fails with the folowing error :

gomobile: loadExportData failed go install -pkgdir=/Users/zoolonly/workspace/goworkspace/pkg/gomobile/pkg_android_arm -tags="" -gcflags=-shared -ldflags=-shared bitbucket.org/avcl/testinggomobile failed: exit status 2
# bitbucket.org/avcl/testinggomobile/testgomobcpp
testgomobcpp/simple.cpp:2:10: fatal error: 'string' file not found

For info, I have installed Android SDK. There is 2 version of NDK installed there plsu the one from gomobile.

echo $ANDROID_HOME
/Users/zoolonly/Library/Android/sdk/

The gomobile bind -target=ios also fails :

gomobile: go install -pkgdir=/Users/zoolonly/workspace/goworkspace/pkg/gomobile/pkg_darwin_arm -tags="" github.com/vrabeux/testinggomobile failed: exit status 2
# github.com/vrabeux/testinggomobile/testgomobcpp
ld: warning: ignoring file $WORK/github.com/vrabeux/testinggomobile/testgomobcpp/_obj/simple.cpp.o, file was built for x86_64 which is not the architecture being linked (armv7): $WORK/github.com/vrabeux/testinggomobile/testgomobcpp/_obj/simple.cpp.o
[....]

Thanks for your help !

@quentinmit quentinmit added this to the Unreleased milestone Oct 6, 2016
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
@jlouazel
Copy link

jlouazel commented Oct 6, 2017

Did someone succeed to do so?

@jlouazel
Copy link

@vrabeux By any chance, did you succeed to get over this issue?

@EtienneL
Copy link

@jlouazel No sorry, I did not find a solution for this. However, you can easily "inject" C++ into your golang mobile SDK via a C++ <-> ObjC++ <-> ObjC <-> Go. Not perfect of course, but it does work.

Hope it helps

@eliasnaur
Copy link
Contributor

Please provide me with a (small) complete example that demonstrates the issue. Also, make sure you use Go 1.10 and run go get -u golang.org/x/mobile/cmd/... first to ensure that gomobile is updated.

@tadovas
Copy link

tadovas commented Sep 12, 2018

The problem is with env variables (how gomobile passes them to go build when crosscompiling to ios):
Here is the link to the patch, which fixed the problem: golang/mobile@c6ae098

A short summary:

  1. Clang++ needs to be called to handle .cpp files (therefore CXX needs to be setup correctly) - clang can compile .cpp too, but a lot of issues will be generated on link phase as go build correctly detects that cpp was used, and links with clang++ with auto included standart c++ libraries
  2. CGO_CXXFLAGS should receive arch we are building for ( ignores arm7 therefore warning about ignoring file build for x86_64 (default arch for clang) when linking for arm7

@eliasnaur
Copy link
Contributor

Thank you. Can you submit a pull request so I can review and merge your fix?

@tadovas
Copy link

tadovas commented Sep 12, 2018

Absolutely. golang/mobile#20

@dmitshur
Copy link
Contributor

This issue was resolved by CL 134975, but didn't get closed automatically because the commit message wasn't using the pattern described at https://golang.org/wiki/CommitMessage#other-repos.

@golang golang locked and limited conversation to collaborators Sep 18, 2019
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

8 participants