gpt4 book ai didi

go - 为什么我不能导入 pkg "builtin"?

转载 作者:IT王子 更新时间:2023-10-29 01:25:30 27 4
gpt4 key购买 nike

猫测试.go

package main

import "builtin"

func main() {
return
}

去运行test.go

can't find import: "builtin"

我只是好奇,因为该文件存在并且已正确打包。但不能像其他包一样导入。

/usr/local/go/src/pkg/builtin/builtin.go

最佳答案

您不需要导入它。默认导入。

来自 http://golang.org/pkg/builtin :

Package builtin provides documentation for Go's predeclared identifiers. The items documented here are not actually in package builtin but their descriptions here allow godoc to present documentation for the language's special identifiers. 

来自 golang.org/pkg/builtin)

如果你看一下http://golang.org/src/pkg/builtin/builtin.go的内容你会注意到只有声明

    // The copy built-in function copies elements from a source slice into a
// destination slice. (As a special case, it also will copy bytes from a
// string to a slice of bytes.) The source and destination may overlap. Copy
// returns the number of elements copied, which will be the minimum of
// len(src) and len(dst).
func copy(dst, src []Type) int

正如@Anonymous 所说,编译器会跳过它: http://golang.org/src/cmd/go/build.go?#L558

       if p.Standard {
switch p.ImportPath {

case "builtin", "unsafe":
// Fake packages - nothing to build.
return a
}

// gccgo standard library is "fake" too.
if _, ok := buildToolchain.(gccgoToolchain); ok {
// the target name is needed for cgo.
a.target = p.target
return a
}
}

关于go - 为什么我不能导入 pkg "builtin"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23994595/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com