lxc / go-lxc

Go bindings for liblxc
https://linuxcontainers.org/lxc
Other
431 stars 76 forks source link

go-lxc fails with gccgo #33

Closed stgraber closed 9 years ago

stgraber commented 9 years ago

I'm looking into gccgo as a way to build LXD for ppc64el and arm64 where gc doesn't work.

So far it looks like most of our code is fine, but go-lxc itself fails when building using gccgo5.

Here's as simple an example as I could come up with:

ubuntu@lantea:~/go/gopkg.in/lxc/go-lxc.v2/examples$ go install -v console.go 
gopkg.in/lxc/go-lxc.v2
command-line-arguments

ubuntu@lantea:~/go/gopkg.in/lxc/go-lxc.v2/examples$ rm -Rf $GOBIN
ubuntu@lantea:~/go/gopkg.in/lxc/go-lxc.v2/examples$ sudo update-alternatives --config go
There are 2 choices for the alternative go (providing /usr/bin/go).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/golang-go   10        auto mode
  1            /usr/bin/gccgo-go    5         manual mode
  2            /usr/bin/golang-go   10        manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/gccgo-go to provide /usr/bin/go (go) in manual mode

ubuntu@lantea:~/go/gopkg.in/lxc/go-lxc.v2/examples$ go install -v console.go 
command-line-arguments
# command-line-arguments
./console.go:13:24: error: redefinition of ‘lxc’
  "gopkg.in/lxc/go-lxc.v2"
                        ^
./console.go:13:24: note: previous definition of ‘lxc’ was here
stgraber commented 9 years ago

ok, so the main failure can be fixed with the following changes:

I'm now getting:

ubuntu@lantea:~/lxd-0.0$ gccgo-go install -v github.com/lxc/lxd/lxc
github.com/lxc/lxd/lxc
# github.com/lxc/lxd/lxc
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:37: error: undefined reference to 'list_active_containers'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:43: error: undefined reference to 'list_all_containers'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:49: error: undefined reference to 'list_defined_containers'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:55: error: undefined reference to 'lxc_container_get'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:61: error: undefined reference to 'lxc_container_new'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:67: error: undefined reference to 'lxc_container_put'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:73: error: undefined reference to 'lxc_get_global_config_item'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.go:79: error: undefined reference to 'lxc_get_version'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.c:232: error: undefined reference to 'lxc_attach_run_shell'
/home/ubuntu/lxd-0.0/dist/src/gopkg.in/lxc/go-lxc.v2/lxc-binding.c:236: error: undefined reference to 'lxc_wait_for_pid_status'
collect2: error: ld returned 1 exit status

Which to me looks like -llxc wasn't passed through to ld somehow.

stgraber commented 9 years ago

Apparently that's because gccgo ignores or fails to parse the pkg-config line, manually setting LDFLAGS fixes it... I'll send a branch with both changes.