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: gomobile fails with linker error #24058

Closed
axet opened this issue Feb 23, 2018 · 3 comments
Closed

x/mobile: gomobile fails with linker error #24058

axet opened this issue Feb 23, 2018 · 3 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@axet
Copy link

axet commented Feb 23, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"

What did you do?

trying to compile https://gitlab.com/axet/libtorrent with following error

# github.com/anacrolix/go-libutp
/var/folders/lv/m63vrmx5375dgk4jhc05ww000000gn/T/go-build072150581/b125/_x008.o(.ARM.extab+0x0): error: undefined reference to '__gxx_personality_v0'
/var/folders/lv/m63vrmx5375dgk4jhc05ww000000gn/T/go-build072150581/b125/_x008.o(.ARM.extab+0x38): error: undefined reference to '__gxx_personality_v0'
/var/folders/lv/m63vrmx5375dgk4jhc05ww000000gn/T/go-build072150581/b125/_x008.o(.ARM.extab+0x64): error: undefined reference to '__gxx_personality_v0'
/var/folders/lv/m63vrmx5375dgk4jhc05ww000000gn/T/go-build072150581/b125/_x008.o(.ARM.extab+0x9c): error: undefined reference to '__gxx_personality_v0'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

My first guess this is gomobile issues. According to https://stackoverflow.com/questions/6045809 here something wrong with -lstdcpp definition.

Adding #cgo LDFLAGS: -lstdc++ to the https://github.com/anacrolix/go-libutp/blob/master/utp.go does not solve the issue.

@ALTree ALTree changed the title gomobile failed x/mobile: gomobile fails with linker error Feb 23, 2018
@gopherbot gopherbot added this to the Unreleased milestone Feb 23, 2018
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 23, 2018
@eliasnaur
Copy link
Contributor

It seems the library doesn't build:

$ CGO_ENABLED=1 CC=<ndk>/clang CXX=<ndk>/clang++ GOOS=android GOARCH=arm go get -u gitlab.com/axet/libtorrent 
# gitlab.com/axet/libtorrent
../dev/go/src/gitlab.com/axet/libtorrent/files.go:52:27: too many arguments in call to t.Files
	have (string)
	want ()
../dev/go/src/gitlab.com/axet/libtorrent/files.go:72:26: t.PieceBytesCompleted undefined (type *torrent.Torrent has no field or method PieceBytesCompleted)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:73:13: t.PieceLength undefined (type *torrent.Torrent has no field or method PieceLength, but does have torrent.pieceLength)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:77:14: t.PieceBytesCompleted undefined (type *torrent.Torrent has no field or method PieceBytesCompleted)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:77:39: t.PieceLength undefined (type *torrent.Torrent has no field or method PieceLength, but does have torrent.pieceLength)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:77:58: t.PieceBytesCompleted undefined (type *torrent.Torrent has no field or method PieceBytesCompleted)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:77:83: t.PieceLength undefined (type *torrent.Torrent has no field or method PieceLength, but does have torrent.pieceLength)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:258:10: t.GetPendingPieces undefined (type *torrent.Torrent has no field or method GetPendingPieces)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:301:3: t.UpdatePiecePriorities undefined (type *torrent.Torrent has no field or method UpdatePiecePriorities, but does have torrent.updatePiecePriorities)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:353:9: t.PieceLength undefined (type *torrent.Torrent has no field or method PieceLength, but does have torrent.pieceLength)
../dev/go/src/gitlab.com/axet/libtorrent/files.go:353:9: too many errors

@axet
Copy link
Author

axet commented Mar 14, 2018

I probably should create simple cpp project to test 'undefined reference', 'dev' branch compiles. Since goland does not support version control for imported code those are common complications build success or failed...

I guess you can just run:

 gomobile bind -o "libtorrent.aar" github.com/anacrolix/go-libutp

@gopherbot
Copy link

Change https://golang.org/cl/99875 mentions this issue: cmd/gomobile: drop init step for build and bind commands

@golang golang locked and limited conversation to collaborators Mar 26, 2019
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
Issue golang/go#24058 demonstrates a Go package that fails to build with
gomobile but builds successfully with a manually using the standalone NDK
toolchain. I haven't been able to figure out a set of CPPFLAGS/LDFLAGS
that fixes the build for 24058 so instead rework gomobile to use
standalone NDK toolchains.

Standalone toolchains fixes the 24058 build and is the official way
to build Android programs. So gomobile should be less affected by
future changes in the NDK toolchain internals.

Create the standalone toolchains with gomobile init.

With the new Go 1.10 build cache, the prebuild work by the gomobile
init command is useless. Use the opportunity to simplify init to
only creating NDK toolchains and, optionally, building OpenAL for
Android. With that, it is no longer necessary to use gomobile init
to build iOS apps and frameworks.

Fixes golang/go#24058

Change-Id: I4692fcaa927e7076a6387d080ebc1726905afd72
Reviewed-on: https://go-review.googlesource.com/99875
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
Issue golang/go#24058 demonstrates a Go package that fails to build with
gomobile but builds successfully with a manually using the standalone NDK
toolchain. I haven't been able to figure out a set of CPPFLAGS/LDFLAGS
that fixes the build for 24058 so instead rework gomobile to use
standalone NDK toolchains.

Standalone toolchains fixes the 24058 build and is the official way
to build Android programs. So gomobile should be less affected by
future changes in the NDK toolchain internals.

Create the standalone toolchains with gomobile init.

With the new Go 1.10 build cache, the prebuild work by the gomobile
init command is useless. Use the opportunity to simplify init to
only creating NDK toolchains and, optionally, building OpenAL for
Android. With that, it is no longer necessary to use gomobile init
to build iOS apps and frameworks.

Fixes golang/go#24058

Change-Id: I4692fcaa927e7076a6387d080ebc1726905afd72
Reviewed-on: https://go-review.googlesource.com/99875
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
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

3 participants