lxc / go-lxc

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

[dontmerge][rfc] Try to make static linking work (fails) #130

Closed hallyn closed 5 years ago

hallyn commented 5 years ago

Hi @caglar10ur

I'm trying to get github.com/lxc/crio-lxc with PR 15 to build. It's doing a static build and importing go-lxc. When I add -x to the go build line, I see

TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b055=/tmp/go-build -gno-record-gcc-switches -o $WORK/b055/_cgo_.o $WORK/b055/_cgo_main.o $WORK/b055/_x001.o $WORK/b055/_x002.o $WORK/b055/_x003.o $WORK/b055/_x004.o $WORK/b055/_x005.o $WORK/b055/_x006.o $WORK/b055/_x007.o -g -O2 -static -llxc -lseccomp -lutil -lcap -llxc -lutil

but i've added libselinux to the pkg-config line here, as well as in crio-lxc's internal.go. On the system where I'm building,

ubuntu@criolxc:~/crio-lxc$ pkg-config --libs libselinux
-lselinux

So why am I not seeing -lselinux in the gcc command being done by 'go build' above?

hallyn commented 5 years ago

Hm, @CajuM says he does get libselinx on his build line. I must have something whacky in my environment, but I have no idea what. Using golang 1.11.5 on ubuntu disco.

CajuM commented 5 years ago

With the following patch applied on master ld ends up complaining about missing p11-kit symbols, but there is no static version of libp11-kit in disco

diff --git a/linking_dynamic.go b/linking_dynamic.go
deleted file mode 100644
index 1197b81..0000000
--- a/linking_dynamic.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright <C2><A9> 2013, 2014, The Go-LXC Authors. All rights reserved.
-// Use of this source code is governed by a LGPLv2.1
-// license that can be found in the LICENSE file.
-
-// +build linux,cgo,!static_build
-
-package lxc
-
-// #cgo LDFLAGS: -llxc -lutil
-import "C"
diff --git a/linking_static.go b/linking_static.go
index 89f06b4..5b08adb 100644
--- a/linking_static.go
+++ b/linking_static.go
@@ -6,5 +6,5 @@

 package lxc

-// #cgo LDFLAGS: -static -llxc -lseccomp -lutil -lcap
+// #cgo LDFLAGS: -static -llxc -lutil -lcap -lselinux -lseccomp -lgnutls -lgmp -lidn2 -lunistring -lhogweed -lgmp -lnettle -ltasn1 -lz
 import "C"
hallyn commented 5 years ago

Ok, thanks, guys. I think I'll spend some more time in a few weeks on the general static linking issue, but for now I can't.