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: bind framework not found by Xcode #35641

Closed
pontusntengnas opened this issue Nov 16, 2019 · 17 comments
Closed

x/mobile: bind framework not found by Xcode #35641

pontusntengnas opened this issue Nov 16, 2019 · 17 comments

Comments

@pontusntengnas
Copy link

@pontusntengnas pontusntengnas commented Nov 16, 2019

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

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

I believe I am on the latest version

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pontusnt/Library/Caches/go-build"
GOENV="/Users/pontusnt/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="MY_GO_PATH"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/68/_7g0dkds1zx17wwpnmh6k4wr0000gn/T/go-build239061966=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

gomobile bind -o frameworks/ios/Shared.framework -target=ios

This completed successfully and I got a folder named Shared.Framework with obj-c files.

I drag and drop this into Xcode 11.2.1 (11B500) to use it in my app.

What did you expect to see?

I expected to be able to compile the app and use the framework in my Swift code.

What did you see instead?

The Xcode project no longer compiles, but fails with:

ld: framework not found Shared clang: error: linker command failed with exit code 1 (use -v to see invocation)

I alos tried adding the absolut path to Xcode build setting Framework search paths without success.

Thankful for your help!

@gopherbot gopherbot added this to the Unreleased milestone Nov 16, 2019
@gopherbot gopherbot added the mobile label Nov 16, 2019
@andybons
Copy link
Member

@andybons andybons commented Nov 18, 2019

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Nov 18, 2019

I alos tried adding the absolut path to Xcode build setting Framework search paths without success.

FWIW, this works for me in Xcode 11.1. Did you add the path to the framework ("/path/to/Shared.framework") or the path to the containing directory ("/path/to")? Xcode expects the latter.

@pontusntengnas
Copy link
Author

@pontusntengnas pontusntengnas commented Nov 18, 2019

Thanks for you reply. I tried both of them without success. I really cannot understand why this is happening, there is a framework in that folder. I do not know if it matters but it is just a folder called "Shared.Framework" containing the files and not that "Lego-ish" icon that i have seen some frameworks have.

The app is targeting iOS 13.

I get the exact same issue trying to use the example at
go get -d golang.org/x/mobile/example/bind/...

@pontusntengnas
Copy link
Author

@pontusntengnas pontusntengnas commented Nov 18, 2019

Am I missing something? I drag n drop the framework into Xcode and it shows up nicely under "Frameworks, Libraries, and embedded content". Then I added the framework search path and tried to build.

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Nov 18, 2019

I installed Xcode 11.2.1 with no change: the bind example builds successfully.

Thanks for you reply. I tried both of them without success. I really cannot understand why this is happening, there is a framework in that folder. I do not know if it matters but it is just a folder called "Shared.Framework" containing the files and not that "Lego-ish" icon that i have seen some frameworks have.

Did you name the framework "Shared.Framework" or "Shared.framework"?

@pontusntengnas
Copy link
Author

@pontusntengnas pontusntengnas commented Nov 19, 2019

I am using "Shared.framework". Capital F gives me an error when binding.

@pontusntengnas
Copy link
Author

@pontusntengnas pontusntengnas commented Nov 24, 2019

Okey I got it working now! What was causing the issue was probably my use of the name "Shared" when there where no Go package called "shared" in the files I was binding.

If i omit the naming of the output -o and just bind it, the frameworks gets a different name but this frameworks gets found by Xcode and can be used, awesome!

But then a follow up question, is it not possible to name my framework to something custom?

In my case I am binding 3 different Go packages and want to create a single output framework of that. I do this like this:

gomobile bind -target=ios \ services/departure \ services/search \ presenters

And then the name of the framework becomes Departure, so I guess it just gets the name of the first package argument I give to bind.

So it works but it would be nice to name it something else. And am I doing it right when binding my 3 packages like I do?

Thanks.

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Nov 24, 2019

Can you send a complete example, with you xcode project ready to use and a set of packages for gomobile bind? The easier it is to reproduce, the better.

@hajimehoshi

@pontusntengnas
Copy link
Author

@pontusntengnas pontusntengnas commented Nov 24, 2019

I do not see it is as necessary as it is working for me now. Now I just wonder if I can have a custom name on the .framework output and if the way I am binding the three packages is the correct way to do it, see my above comment.

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Nov 24, 2019

@pontusntengnas
Copy link
Author

@pontusntengnas pontusntengnas commented Nov 25, 2019

Ok I see I will try to find time to make an example and attach here.

@arjenveenhuizen
Copy link

@arjenveenhuizen arjenveenhuizen commented Feb 18, 2020

We ran into the same issue when upgrading from xcode 10.3 to 11.3.1. Module not found whatever we tried or change on our gomobile bind command line.

Triggered by #35641 (comment) we finally figured out that we had to change the Framework Search Paths from $(SRCROOT)/../../../path/to/Myframework.framework/ to $(SRCROOT)/../../../path/to/

@cooolinx
Copy link

@cooolinx cooolinx commented Jun 13, 2020

I ran into the same issue today, and thanks to @pontusntengnas , I resolve it by omitting -o option.

I made a simple example and hope it helps @eliasnaur

Env

  • go version go1.14.3 darwin/amd64
  • Xcode 11.5
  • macOS Catalina 10.15.4
go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/guolin/Library/Caches/go-build"
GOENV="/Users/guolin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/guolin/Work/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/Cellar/go/1.14.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/guolin/Work/colin/go/issue/gogo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0k/r288ywwx49zcyx8dpgh5tt5r0000gn/T/go-build768315077=/tmp/go-build -gno-record-gcc-switches -fno-common"

Reproduce

Download the issue.zip file then extract, will get two projects:

  • gogo for Go
  • Soso for Xcode
  1. Build gogo:
cd gogo
gomobile bind -o gogo.framework -a -ldflags '-s -w' -target=ios gogo.go/fly gogo.go/swim
  1. Open Soso project by Xcode
  2. Add gogo.framework into Xcode project
  3. Press Command+Shift+R to build project will see the error: Framework not found gogo

hope it helps

@ToJen
Copy link

@ToJen ToJen commented Jun 19, 2020

It appears that if the framework name is different from the name of the package that was built, this ld not found error will be thrown.
In "Example.framework/Versions/A/Modules/module.modulemap" you should see something like this:

framework module "Example" {
	header "ref.h"
    header "Example.objc.h"
    header "Universe.objc.h"
    header "Example.h"

    export *
}

I notice that Example.framework won't work if the root module I'm trying to import is not called Example. So if the first line of that snippet is framework module "Random" you can't import from Example, only Random.

So it kinda makes sense that when @Fallenlord removed -o it worked because gomobile will have used the actual package name which you would use when importing. Could this be a bug in gomobile? If so, I think the framework name from the -o flag should take precedence over the golang package name being bound.

@hajimehoshi
Copy link
Member

@hajimehoshi hajimehoshi commented Jun 20, 2020

So, fixing modulemap by using the specified framework name would solve this issue? That makes sense. I'll take a look next week.

@ToJen
Copy link

@ToJen ToJen commented Jun 20, 2020

That’s my guess. It may need testing on Android and iOS apps. Happy to spend some time contributing to that @hajimehoshi.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 22, 2020

Change https://golang.org/cl/239237 mentions this issue: cmd/gomobile: use the specified output name for the module name on iOS

roderm added a commit to roderm/mobile that referenced this issue Sep 13, 2020
When the module name in *.modulemap and the framework name don't match,
Xcode fails to find the framework.

This CL fixes this issue by using the specified .framework name for the
module name.

Fixes golang/go#35641

Change-Id: I0df5335f2d64f0529e7357c2d04af5eaf760a879
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/239237
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.