登录
首页 >  Golang >  Go问答

为何无法找到Go这些源文件?

来源:stackoverflow

时间:2024-03-12 18:33:32 244浏览 收藏

Golang不知道大家是否熟悉?今天我将给大家介绍《为何无法找到Go这些源文件?》,这篇文章主要会讲到等等知识点,如果你在看完本篇文章后,有更好的建议或者发现哪里有问题,希望大家都能积极评论指出,谢谢!希望我们能一起加油进步!

问题内容

我正在尝试在树莓派上编译 kaniko。

我不会用 golang 编程,但几周前我能够在同一个树莓派上成功编译 kaniko,甚至给自己写了一份遵循步骤的指南,但现在,遵循相同的步骤,有些东西坏了。

kaiko 需要 go,但是在树莓派存储库中找到了更新版本的 go,所以我从头开始下载并安装 gogo 需要 go 进行编译,因此我首先从存储库安装它(旧版本),然后在编译完自身的更新版本后将其删除:

安装go

sudo apt-get install golang
wget https://dl.google.com/go/go1.17.6.src.tar.gz 
tar -xvf go1.17.6.src.tar.gz
cd go/src
./make.bash
sudo apt-get purge golang golang-go
sudo mv -v ../bin/* /usr/local/bin
echo 'export gopath=~/.go' >> ~/.profile
echo 'export goroot=/usr/local/bin' >> ~/.profile
source ~/.profile

编译kaniko:

sudo apt-get install git
git clone https://github.com/googlecontainertools/kaniko.git
cd kaniko
make

我得到的是这样的:

GOARCH=arm GOOS=linux CGO_ENABLED=0 go build -ldflags '-extldflags "-static" -X github.com/GoogleContainerTools/kaniko/pkg/version.version=v1.7.0 -w -s  ' -o out/executor github.com/GoogleContainerTools/kaniko/cmd/executor
pkg/util/fs_util.go:20:2: cannot find package "." in:
    /home/pi/kaniko/vendor/archive/tar
vendor/google.golang.org/grpc/internal/binarylog/sink.go:22:2: cannot find package "." in:
    /home/pi/kaniko/vendor/bufio
vendor/cloud.google.com/go/storage/storage.go:18:2: cannot find package "." in:
    /home/pi/kaniko/vendor/bytes
pkg/util/tar_util.go:21:2: cannot find package "." in:
    /home/pi/kaniko/vendor/compress/bzip2
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/compressed.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/compress/flate
vendor/google.golang.org/protobuf/internal/impl/legacy_file.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/compress/gzip
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/compressed.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/compress/zlib
vendor/golang.org/x/text/unicode/bidi/bracket.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/container/list
vendor/cloud.google.com/go/compute/metadata/metadata.go:23:2: cannot find package "." in:
    /home/pi/kaniko/vendor/context
vendor/golang.org/x/oauth2/jws/jws.go:19:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto
vendor/google.golang.org/grpc/credentials/alts/internal/conn/aeadrekey.go:23:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/aes
vendor/google.golang.org/grpc/credentials/alts/internal/conn/aeadrekey.go:24:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/cipher
vendor/github.com/ProtonMail/go-crypto/openpgp/internal/algorithm/cipher.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/des
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/private_key.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/dsa
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/private_key.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/ecdsa
vendor/golang.org/x/crypto/ed25519/ed25519_go113.go:23:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/ed25519
vendor/github.com/ProtonMail/go-crypto/openpgp/ecdh/ecdh.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/elliptic
vendor/golang.org/x/oauth2/google/internal/externalaccount/aws.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/hmac
vendor/github.com/google/uuid/hash.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/md5
vendor/golang.org/x/net/http2/transport.go:14:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/rand
vendor/golang.org/x/crypto/ssh/cipher.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/rc4
vendor/golang.org/x/oauth2/internal/oauth2.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/rsa
vendor/github.com/google/uuid/hash.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/sha1
vendor/golang.org/x/oauth2/google/internal/externalaccount/aws.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/sha256
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/public_key.go:15:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/sha512
vendor/github.com/ProtonMail/go-crypto/eax/eax.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/subtle
vendor/google.golang.org/grpc/credentials/tls.go:23:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/tls
vendor/google.golang.org/grpc/credentials/tls.go:24:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/x509
vendor/golang.org/x/crypto/pkcs12/crypto.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/crypto/x509/pkix
vendor/github.com/google/uuid/null.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/database/sql/driver
vendor/github.com/cilium/ebpf/elf_reader.go:6:2: cannot find package "." in:
    /home/pi/kaniko/vendor/debug/elf
vendor/github.com/golang/protobuf/proto/text_decode.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/signature.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/asn1
vendor/google.golang.org/protobuf/encoding/protojson/decode.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/base64
vendor/google.golang.org/protobuf/internal/detrand/rand.go:13:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/binary
vendor/github.com/moby/buildkit/frontend/dockerfile/instructions/commands_runmount.go:4:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/csv
vendor/github.com/go-git/gcfg/set.go:5:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/gob
vendor/golang.org/x/oauth2/google/internal/externalaccount/aws.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/hex
vendor/cloud.google.com/go/compute/metadata/metadata.go:24:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/json
vendor/golang.org/x/oauth2/internal/oauth2.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/pem
vendor/github.com/Azure/azure-storage-blob-go/azblob/zc_storage_error.go:5:2: cannot find package "." in:
    /home/pi/kaniko/vendor/encoding/xml
vendor/google.golang.org/protobuf/internal/errors/errors.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/errors
vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go:18:2: cannot find package "." in:
    /home/pi/kaniko/vendor/expvar
vendor/github.com/docker/docker/pkg/chrootarchive/archive_unix.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/flag
cmd/executor/cmd/root.go:20:2: cannot find package "." in:
    /home/pi/kaniko/vendor/fmt
vendor/github.com/cilium/ebpf/internal/output.go:6:2: cannot find package "." in:
    /home/pi/kaniko/vendor/go/format
vendor/github.com/cilium/ebpf/internal/output.go:7:2: cannot find package "." in:
    /home/pi/kaniko/vendor/go/scanner
vendor/google.golang.org/protobuf/internal/strs/strings.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/go/token
vendor/github.com/google/uuid/hash.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/hash
vendor/google.golang.org/protobuf/internal/impl/legacy_export.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/hash/crc32
vendor/github.com/vbatts/tar-split/tar/storage/getter.go:6:2: cannot find package "." in:
    /home/pi/kaniko/vendor/hash/crc64
vendor/google.golang.org/protobuf/internal/detrand/rand.go:14:2: cannot find package "." in:
    /home/pi/kaniko/vendor/hash/fnv
vendor/github.com/sergi/go-diff/diffmatchpatch/diff.go:15:2: cannot find package "." in:
    /home/pi/kaniko/vendor/html
vendor/golang.org/x/net/trace/events.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/html/template
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/userattribute.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/image
vendor/github.com/ProtonMail/go-crypto/openpgp/packet/userattribute.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/image/jpeg
vendor/cloud.google.com/go/compute/metadata/retry.go:19:2: cannot find package "." in:
    /home/pi/kaniko/vendor/io
vendor/github.com/opencontainers/selinux/pkg/pwalkdir/pwalkdir.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/io/fs
vendor/cloud.google.com/go/compute/metadata/metadata.go:26:2: cannot find package "." in:
    /home/pi/kaniko/vendor/io/ioutil
vendor/golang.org/x/net/internal/timeseries/timeseries.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/log
vendor/github.com/Azure/azure-pipeline-go/pipeline/defaultlog_syslog.go:7:2: cannot find package "." in:
    /home/pi/kaniko/vendor/log/syslog
vendor/google.golang.org/protobuf/encoding/protowire/wire.go:14:2: cannot find package "." in:
    /home/pi/kaniko/vendor/math
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/unmarshal.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/math/big
vendor/google.golang.org/protobuf/encoding/protowire/wire.go:15:2: cannot find package "." in:
    /home/pi/kaniko/vendor/math/bits
vendor/cloud.google.com/go/compute/metadata/retry.go:20:2: cannot find package "." in:
    /home/pi/kaniko/vendor/math/rand
vendor/golang.org/x/oauth2/internal/token.go:15:2: cannot find package "." in:
    /home/pi/kaniko/vendor/mime
vendor/google.golang.org/api/internal/gensupport/media.go:13:2: cannot find package "." in:
    /home/pi/kaniko/vendor/mime/multipart
vendor/cloud.google.com/go/compute/metadata/metadata.go:27:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net
vendor/cloud.google.com/go/compute/metadata/metadata.go:28:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net/http
vendor/github.com/Azure/go-autorest/autorest/adal/sender.go:21:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net/http/cookiejar
vendor/golang.org/x/net/http2/go111.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net/http/httptrace
vendor/google.golang.org/grpc/internal/transport/proxy.go:29:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net/http/httputil
vendor/golang.org/x/net/http/httpguts/guts.go:13:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net/textproto
vendor/cloud.google.com/go/compute/metadata/metadata.go:29:2: cannot find package "." in:
    /home/pi/kaniko/vendor/net/url
vendor/cloud.google.com/go/compute/metadata/metadata.go:30:2: cannot find package "." in:
    /home/pi/kaniko/vendor/os
vendor/google.golang.org/api/transport/cert/default_cert.go:23:2: cannot find package "." in:
    /home/pi/kaniko/vendor/os/exec
vendor/github.com/moby/term/term.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/os/signal
vendor/golang.org/x/oauth2/google/sdk.go:16:2: cannot find package "." in:
    /home/pi/kaniko/vendor/os/user
vendor/golang.org/x/oauth2/google/internal/externalaccount/aws.go:21:2: cannot find package "." in:
    /home/pi/kaniko/vendor/path
vendor/google.golang.org/grpc/internal/transport/http2_client.go:28:2: cannot find package "." in:
    /home/pi/kaniko/vendor/path/filepath
vendor/google.golang.org/protobuf/internal/descfmt/stringer.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/reflect
vendor/google.golang.org/protobuf/internal/encoding/text/decode.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/regexp
vendor/cloud.google.com/go/compute/metadata/metadata.go:31:2: cannot find package "." in:
    /home/pi/kaniko/vendor/runtime
vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/useragent.go:20:2: cannot find package "." in:
    /home/pi/kaniko/vendor/runtime/debug
vendor/github.com/prometheus/client_golang/prometheus/internal/go_runtime_metrics.go:21:2: cannot find package "." in:
    /home/pi/kaniko/vendor/runtime/metrics
vendor/go.opencensus.io/tag/profile_19.go:21:2: cannot find package "." in:
    /home/pi/kaniko/vendor/runtime/pprof
vendor/go.opencensus.io/trace/trace_go11.go:21:2: cannot find package "." in:
    /home/pi/kaniko/vendor/runtime/trace
vendor/google.golang.org/protobuf/internal/order/range.go:9:2: cannot find package "." in:
    /home/pi/kaniko/vendor/sort
vendor/google.golang.org/protobuf/reflect/protoreflect/source.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/strconv
vendor/cloud.google.com/go/compute/metadata/metadata.go:32:2: cannot find package "." in:
    /home/pi/kaniko/vendor/strings
vendor/cloud.google.com/go/compute/metadata/metadata.go:33:2: cannot find package "." in:
    /home/pi/kaniko/vendor/sync
vendor/google.golang.org/protobuf/internal/filedesc/desc.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/sync/atomic
vendor/cloud.google.com/go/compute/metadata/retry_linux.go:20:8: cannot find package "." in:
    /home/pi/kaniko/vendor/syscall
vendor/github.com/otiai10/copy/test_setup.go:8:2: cannot find package "." in:
    /home/pi/kaniko/vendor/testing
vendor/github.com/docker/docker/pkg/fileutils/fileutils.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/text/scanner
vendor/golang.org/x/net/trace/events.go:20:2: cannot find package "." in:
    /home/pi/kaniko/vendor/text/tabwriter
pkg/timing/timing.go:23:2: cannot find package "." in:
    /home/pi/kaniko/vendor/text/template
vendor/cloud.google.com/go/compute/metadata/metadata.go:34:2: cannot find package "." in:
    /home/pi/kaniko/vendor/time
vendor/google.golang.org/protobuf/internal/strs/strings.go:11:2: cannot find package "." in:
    /home/pi/kaniko/vendor/unicode
vendor/google.golang.org/protobuf/internal/encoding/text/decode_string.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/unicode/utf16
vendor/google.golang.org/protobuf/internal/strs/strings.go:12:2: cannot find package "." in:
    /home/pi/kaniko/vendor/unicode/utf8
vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go:10:2: cannot find package "." in:
    /home/pi/kaniko/vendor/unsafe
make: *** [Makefile:51: out/executor] Error 1

go 似乎找不到 kaniko 源代码。这是为什么?我做错了什么?


正确答案


根据评论,我的建议是将 $HOME/go/bin 添加到路径并使用默认的 GOPATH。

Go mod 依赖于 GOPATH 中的 bin 目录。它在那里安装新的软件包。 go 二进制文件本身实际上可以驻留在其他地方。如果您遵循这些安装指令 https://go.dev/doc/install,go 本身实际上将位于 /usr/local/go 中,但 GOPATH 仍然是 $HOME/go

我还建议,根本不涉及 apt 。这看起来像是与不同安装发生冲突的麻烦。

好了,本文到此结束,带大家了解了《为何无法找到Go这些源文件?》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>