Tag: cgo

在Kubernetes集群上没有CGO的Golang DNS

我用Golang写了一个api,并部署在一个Kubernetes集群中。 这意味着它运行在一个docker容器与临时图像。 要编译成像scratch / alpine这样的光图像,我需要closurescgo。 但是,如果没有cgo,networking包将无法正常工作。 我知道networking包有一个问题,因为它本身使用cgo。 我需要为这个应用程序使用的所有服务都在另一个Kubernetes命名空间,所以唯一的办法就是使用DNS。 我在这里的一个angular落。 我用这样的东西来构build二进制文件 GOOS='linux' CGO_ENABLED=0 GODEBUG=netdns=go+1 go build -a -installsuffix cgo -ldflags -s -o ./dist/prod/api ./src/backend/api.go 这本身并不能解决问题,但正如布拉德•菲茨帕特里克 ( Brad Fitzpatrick) 在这里所说的那样,这是一个谜团。 我终于得到了它的工作 //Connect is a function that connects to MOngoDB func Connect() (*mgo.Session, error) { var host string if os.Getenv("KUBERNETES") == "true" { cmd := exec.Command("ping", "-c", "1", […]

使用go编译交叉编译CGO_ENABLED – 警告:找不到libudev.so.1

我正在尝试为CGO_ENABLED=1交叉编译Golang应用程序,因为libusb依赖 在编译期间,我得到错误: arm-linux-gnueabihf/bin/ld: warning: libudev.so.1, needed by /usr/lib/arm-linux-gnueabihf/libusb-1.0.so, not found (try using -rpath or -rpath-link) 我已经尝试了下面的命令的多个变种,没有运气: CGO_ENABLED=1 GOARCH=arm GOARM=7 PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ go build -x -ldflags '-extld=arm-linux-gnueabihf-gcc -rpath=/usr/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf -ludev' 当我用-x标志运行这个版本的时候,我得到了详细的输出结果,而且在build立src/net包的时候,它看起来像是失败了。 cd /usr/local/go/src/net /usr/local/go/pkg/tool/linux_amd64/cgo -dynpackage net -dynimport $WORK/net/_obj/_cgo_.o -dynout $WORK/net/_obj/_cgo_import.go arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/net/_obj/_all.o $WORK/net/_obj/_cgo_export.o $WORK/net/_obj/cgo_linux.cgo2.o $WORK/net/_obj/cgo_resnew.cgo2.o $WORK/net/_obj/cgo_socknew.cgo2.o […]