Issue building LXD from release source

I downloaded the 3.20 release source, extracted it, set the Go path and tried to build it but it’s not working for me. make deps completes fine but as soon as I want to build lxd itself I get go errors.

Are the instructions in the README still up-to-date?

root@dream:~/lxd-3.20# make
go get -t -v -d ./...
CC=cc go install -v -tags "libsqlite3"  ./...
go install: no install location for directory /root/lxd-3.20/fuidshift outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxc outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxc-to-lxd outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxd outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxd-agent outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxd-benchmark outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxd-p2c outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/shared/generate outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/test/deps outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/test/macaroon-identity outside GOPATH
	For more details see: 'go help gopath'
Makefile:18: recipe for target 'default' failed
make: *** [default] Error 1
root@dream:~/lxd-3.20# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/lxd-3.20/_dist"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/go.1.13.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/go.1.13.7/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-I/root/lxd-3.20/_dist/deps/sqlite/ -I/root/lxd-3.20/_dist/deps/libco/ -I/root/lxd-3.20/_dist/deps/raft/include/ -I/root/lxd-3.20/_dist/deps/dqlite/include/"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/root/lxd-3.20/_dist/deps/sqlite/.libs/ -L/root/lxd-3.20/_dist/deps/libco/ -L/root/lxd-3.20/_dist/deps/raft/.libs -L/root/lxd-3.20/_dist/deps/dqlite/.libs/"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build420201705=/tmp/go-build -gno-record-gcc-switches"

Hi!

The documentation says

To build an official release of LXD, download and extract a release tarball, and then set up GOPATH to point to the _dist directory inside it, which is configured to be used as a GOPATH and contains snapshots of all necessary sources.

The message you get, says that you did not do the GOPATH thing.

If you check the above output you can see my GOPATH is setup to the _dist folder. Should this be something else?

Sorry if I am a bit thick, but you did not explicilty say that you followed the doc advice to copy and paste the make deps output before running make and not just use the example in the doc.

Good of you to check but I took the output and pasted it in my terminal as well as updated my bashrc with it just in case.

I tried it and I see the same messages (ubuntu 18.04, go installed from snap); setting
export GOBIN=$GOPATH
makes it fail too but later :slight_smile:

Thanks for confirming this for me.

Does you infinite wisdom include a fix for this problem @stgraber ?

When you run make, LXD tries to download the rest of the repositories and place them in /root/lxd-3.20/, which is obviously outside of $GOPATH. Hence the message.

Older versions of Go did not complain about this, and I believe that this is the reason why there is an error now.

A potential workaround would be to set two paths in $GOPATH, ~/go and the _dist one.
So that the repositories that LXD needs, can be placed properly in ~/go, as they can be used by other Go packages. Perhaps this is the missing bit from the documentation?

I’m afraid that doesn’t work neither.

root@dream:~/lxd-3.20# echo $GOPATH
/root/lxd-3.20/_dist:/root/go:/root/lxd-3.20
root@dream:~/lxd-3.20# make
go get -t -v -d ./...
CC=cc go install -v -tags "libsqlite3"  ./...
go install: no install location for directory /root/lxd-3.20/fuidshift outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /root/lxd-3.20/lxc outside GOPATH
...

I wonder if a switch to Go modules could fix this.

I’ve tried it again today with a brand new server, lxd-4.0.0 release but I still can’t build it.

I can’t use the Snap version because of the embedded Ceph version and because auto-updating already broke my cluster at least twice.

Is there somebody that can help me get this to build?

This is what I use:

mkdir -p ~/go/src/github.com/lxc
export GOPATH=~/go
cd ~/go/src/github.com/lxc
git clone git@github.com:lxc/lxd.git
cd lxd
git checkout lxd-4.0.0
go get -d -v github.com/lxc/lxd/lxd
make deps
export CGO_CFLAGS="${CGO_CFLAGS} -I${GOPATH}/deps/sqlite/ -I${GOPATH}/deps/libco/ -I${GOPATH}/deps/raft/include/ -I${GOPATH}/deps/dqlite/include/"
export CGO_LDFLAGS="${CGO_LDFLAGS} -L${GOPATH}/deps/sqlite/.libs/ -L${GOPATH}/deps/libco/ -L${GOPATH}/deps/raft/.libs -L${GOPATH}/deps/dqlite/.libs/"
export LD_LIBRARY_PATH="${GOPATH}/deps/sqlite/.libs/:${GOPATH}/deps/libco/:${GOPATH}/deps/raft/.libs/:${GOPATH}/deps/dqlite/.libs/"
make

Awesome, that seems to have done the trick!

Just had to change git@github.com:lxc/lxd.git to git clone https://github.com/lxc/lxd for anybody else wanting to use this.

This question is a bit related so I’m asking it here.

If I want to use lxc 4.0 together with lxd 4.0 how would I build the former so the latter uses it?

I’m greeted by Error: Common start logic: Failed to start device "eth1": Requires liblxc has following API extensions: network_veth_router, network_l2proxy errors.

For liblxc on ubuntu 18.04 I use:

./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make
sudo make install

Make sure you remove any preinstalled binary packages first for lxc though.

Yup that did the trick, thanks!

1 Like