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: embedding library on iOS build fails. Undefined symbols: Linker command failed with exit code 1 #64758

Open
tomekit opened this issue Dec 15, 2023 · 1 comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tomekit
Copy link

tomekit commented Dec 15, 2023

I am trying to embed librclone library in my iOS Flutter project.
It binds using gomobile just fine, however after I include in the Xcode project, build fails with:

Undefined symbols:
Linker command failed with exit code 1 (use -v to see invocation)

also the resulting ld output doesn't look healthy

# ld ios/Gomobile.xcframework/ios-arm64/Gomobile.framework/Gomobile
ld: warning: platform not specified
ld: warning: -arch not specified
ld: warning: No platform min-version specified on command line
ld: warning: ignoring file Gomobile, file is universal (arm64) but does not contain the unknown architecture: Gomobile
Undefined symbols for architecture unknown:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture unknown
# file ios/Gomobile.xcframework/ios-arm64/Gomobile.framework/Gomobile
Gomobile: Mach-O universal binary with 1 architecture: [arm64:current ar archive]
Gomobile (for architecture arm64):	current ar archive

Reproducible steps

cd /tmp
git clone https://github.com/rclone/rclone.git
cd rclone
git checkout v1.65.0

# Apply some iOS fixes that hasn't landed to master yet
git remote add patch https://github.com/imWildCat/rclone.git
git fetch patch
git cherry-pick db1fa117b87fcf5d1c80aca603d6637b9b9baacb

go install golang.org/x/mobile/cmd/gobind@latest
go install golang.org/x/mobile/cmd/gomobile@latest
env PATH=$PATH:~/go/bin gomobile init
# target either ios or iossimulator
env PATH=$PATH:~/go/bin gomobile bind -v -target=ios ./librclone/gomobile

ld Gomobile.xcframework/ios-arm64/Gomobile.framework/Gomobile

In order to include the generated project I've used these steps:
https://go.dev/wiki/Mobile#building-and-deploying-to-ios-1
also tried couple more from:
https://medium.com/@matryer/tutorial-calling-go-code-from-swift-on-ios-and-vice-versa-with-gomobile-7925620c17a4

Framework Search Paths

Since my librclone library is located at: ~/myproject/ios/Gomobile.xcframework which is outside of the iOS Runner ~myproject/ios/Runner/AppDelegate.swift I've added: ${PROJECT_DIR}/.. to Framework Search Paths

Bitcode

I've got ENABLE_BITCODE set to NO

Versions

go version

go version go1.21.5 darwin/arm64

sw_vers

ProductName:		macOS
ProductVersion:		14.1.1
BuildVersion:		23B81

xcode

XCode Version 15.1 (15C65)

gomobile version

gomobile version unknown: binary is out of date, re-install it

Not sure why gomobile version returns such a version tag. It's freshly installed using: go install golang.org/x/mobile/cmd/gomobile@latest

I would appreciate if you could help me to narrow down where the potential issue might be.

Related: #37241

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Dec 15, 2023
@gopherbot gopherbot added this to the Unreleased milestone Dec 15, 2023
@thanm
Copy link
Contributor

thanm commented Dec 18, 2023

Regarding the version issue, I think this is due to the code here:

https://go.googlesource.com/mobile/+/76ac6878050a2eef81867f2c6c21108e59919e8f/cmd/gomobile/version.go#29

which looks as though it predates module mode. If you download the mobile repo, built it there, and run it, you get something more reasonable.

As far as the other errors: no idea (don't know enough about gomobile).

@hyangah per owners

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 18, 2023
@seankhliao seankhliao changed the title x/mobile: Embedding library on iOS build fails. Undefined symbols: Linker command failed with exit code 1 x/mobile: embedding library on iOS build fails. Undefined symbols: Linker command failed with exit code 1 Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants