我有两个项目,一个是库,另一个是实用程序。我使用go install
来构建库并将其放置在 pkg 区域中。这似乎按预期工作。
sbio $ pwd
/home/mjohn/workspaces/goprojects/src/crown/sbio
sbio $ CC=armv7l-timesys-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go install
sbio $ ls ../../../pkg/linux_arm/crown
sbio.a
我的问题是当我尝试让我的实用程序使用此库时。它抱怨no buildable Go source files
但它在src
目录下查看,这让我认为它在pkg
区域看不到它。我在实用程序中的导入路径是crown/sbio
.任何想法都会有所帮助。
utility $ GOOS=linux GOARCH=arm GOARM=7 go build
go build crown/sbio: no buildable Go source files in /home/mjohn/workspaces/goprojects/src/crown/sbio
utility $ GOOS=linux GOARCH=arm GOARM=7 go build -v -x -work
WORK=/tmp/go-build709862068
crown/sbio
github.com/jessevdk/go-flags
mkdir -p $WORK/github.com/jessevdk/go-flags/_obj/
os/signal
mkdir -p $WORK/github.com/jessevdk/
cd /home/mjohn/workspaces/goprojects/src/github.com/jessevdk/go-flags
/home/mjohn/software/go/pkg/tool/linux_386/compile -o $WORK/github.com/jessevdk/go-flags.a -trimpath $WORK -p github.com/jessevdk/go-flags -complete -buildid 2e7b82d3996437f712d51c2be269e6cd3eb809d6 -D _/home/mjohn/workspaces/goprojects/src/github.com/jessevdk/go-flags -I $WORK -pack ./arg.go ./closest.go ./command.go ./command_private.go ./completion.go ./convert.go ./error.go ./flags.go ./group.go ./group_private.go ./help.go ./ini.go ./ini_private.go ./man.go ./multitag.go ./option.go ./option_private.go ./optstyle_other.go ./parser.go ./parser_private.go ./termsize.go ./termsize_linux.go
mkdir -p $WORK/os/signal/_obj/
mkdir -p $WORK/os/
cd /home/mjohn/software/go/src/os/signal
/home/mjohn/software/go/pkg/tool/linux_386/compile -o $WORK/os/signal.a -trimpath $WORK -p os/signal -buildid 36d5db084a1ab49c3fbb474d340be7996d6606d8 -D _/home/mjohn/software/go/src/os/signal -I $WORK -pack -asmhdr $WORK/os/signal/_obj/go_asm.h ./doc.go ./signal.go ./signal_unix.go
mkdir -p $WORK/crown/sbio/_obj/
mkdir -p $WORK/crown/
go build crown/sbio: no buildable Go source files in /home/mjohn/workspaces/goprojects/src/crown/sbio
/home/mjohn/software/go/pkg/tool/linux_386/asm -o $WORK/os/signal/_obj/sig.o -trimpath $WORK -I $WORK/os/signal/_obj/ -I /home/mjohn/software/go/pkg/include -D GOOS_linux -D GOARCH_arm ./sig.s
pack r $WORK/os/signal.a $WORK/os/signal/_obj/sig.o # internal
utility $ go env
GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mjohn/workspaces/goprojects"
GORACE=""
GOROOT="/home/mjohn/software/go"
GOTOOLDIR="/home/mjohn/software/go/pkg/tool/linux_386"
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build583017880=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
utility $ go version
go version go1.7.4 linux/386
感谢您的任何帮助。
我能够通过定义CC
和CGO_ENABLED
变量构建实用程序来解决我的问题。我需要定义它们来构建实用程序,即使它不包含任何 cgo 代码,但由于库的原因仍然需要它。
如果可以在不需要这样做的情况下构建实用程序,我仍然会感兴趣,因为让库的每个用户都需要定义这些是很痛苦的。