andlabs / ui

Platform-native GUI library for Go.
Other
8.34k stars 648 forks source link

Go get fails on linux_amd64 #180

Closed mixedCase closed 7 years ago

mixedCase commented 8 years ago

Get the following when trying to go get:

$ LANG=C go get -u github.com/andlabs/ui
# github.com/andlabs/ui
/usr/bin/ld: andlabs/ui/libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

LANG=C merely used to have the errors in English.

mixedCase commented 8 years ago

Trying to run the example here after the failed go get also returns the same error.

andlabs commented 8 years ago

What version of Go?

mixedCase commented 8 years ago
$ go version
go version go1.6.3 linux/amd64
joeblew99 commented 8 years ago

how did you install the gcc tools ?

what linux are you on ?

andlabs commented 8 years ago

The binaries might not be built with PIC. I'll need to see how to get cmake to do it, if I didn't already...

mixedCase commented 8 years ago

@joeblew99 Through my distro's package manager. I'm using Arch Linux, GCC is version 6.1.1.

joeblew99 commented 8 years ago

Ok. I am on Ubuntu and used the package manager on Ubuntu.

I am wondering if I can help and land with the cross built. Maybe the xgo github project would help ? I am only guessing about this though.

If others like me would compile everything I could also maybe help with the matching of the c code to the golang code.

emersion commented 8 years ago

xgo works for macOS, but not Windows (see https://github.com/karalabe/xgo/issues/55).

You need the latest mingw-w64 (5.0rc2) which hasn't yet been released.

joeblew99 commented 8 years ago

https://packages.debian.org/search?keywords=mingw-w64

Debian experimental looks to have the mingw-w64 (5.0rc2). Maybe worth trying in a VM ?

joeblew99 commented 8 years ago

Ok thanks Emerson. Looks like I have to wait

mixedCase commented 8 years ago

@andlabs How did you build these .a files and from what?

andlabs commented 8 years ago

Simply with

cmake -DBUILD_SHARED_LIBS=OFF ..
make

on Ubuntu 16.04.

I forget how or if I specified PIC.

mixedCase commented 8 years ago

@andlabs I can confirm that it works if I add -fPIC to libui's compiler instructions in CMakeLists.txt. Could you recompile and upload?

mixedCase commented 7 years ago

Pinging @andlabs in case you missed the last comment.

andlabs commented 7 years ago

I'll look into it soon.

txthinking commented 7 years ago

Should I install mingw-w64 (5.0rc2) and set CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ before go get github.com/andlabs/ui ?

andlabs commented 7 years ago

Yes.

txthinking commented 7 years ago

On Archlinux. installed gtk3.

Go

$ go version
go version go1.7.3 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tx/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build663071203=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

install mingw-w64-crt-git-5.0.rc2.r114.g563731c-1

$ yaourt -S mingw-w64-crt-git

get ui

$ CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go get -v -u github.com/andlabs/ui
github.com/andlabs/ui (download)
github.com/andlabs/ui
# github.com/andlabs/ui
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -ldl
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgtk-3
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgdk-3
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lpangocairo-1.0
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lpango-1.0
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -latk-1.0
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lcairo-gobject
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lcairo
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgio-2.0
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgobject-2.0
/usr/lib/gcc/x86_64-w64-mingw32/6.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lglib-2.0
collect2: error: ld returned 1 exit status
andlabs commented 7 years ago

You must also set $GOOS.

txthinking commented 7 years ago

@andlabs Thanks, it works with mingw-w64-crt-git. #155

NickCao commented 7 years ago

The same issue for me on Ubuntu GNOME 16.10. Not fixed yet.

andlabs commented 7 years ago

What version of MinGW-w64 does Ubuntu 16.10 come with?

NickCao commented 7 years ago

I was just building for Linux, maybe MinGW is not required?

andlabs commented 7 years ago

Do you want to build Linux-native programs or Windows-native programs?

NickCao commented 7 years ago

Linux-native (Sorry for responding so late. I was traveling these days.)

andlabs commented 7 years ago

Then your $GOOS is not set properly. What does go env print?

NickCao commented 7 years ago

GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/nickcao/Projects/Go" GORACE="" GOROOT="/usr/lib/go-1.6" GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"

andlabs commented 7 years ago

Your environment is correct for a Linux build. I'm not sure why it's trying to build the Windows one...

NickCao commented 7 years ago

Maybe building it manually instead of using go get can fix that?

mixedCase commented 7 years ago

Closing this because I no longer have the original issue.