undefined问题
按照文档的方式写了示例代码: package main
import ( "bytes" "fmt" "io/ioutil" "log"
"github.com/chai2010/webp"
)
func main() { var buf bytes.Buffer var width, height int var data []byte var err error
// Load file data
if data, err = ioutil.ReadFile("./testdata/1_webp_ll.webp"); err != nil {
log.Println(err)
}
// GetInfo
if width, height, _, err = webp.GetInfo(data); err != nil {
log.Println(err)
}
fmt.Printf("width = %d, height = %d\n", width, height)
// GetMetadata
if metadata, err := webp.GetMetadata(data, "ICCP"); err != nil {
fmt.Printf("Metadata: err = %v\n", err)
} else {
fmt.Printf("Metadata: %s\n", string(metadata))
}
// Decode webp
m, err := webp.Decode(bytes.NewReader(data))
if err != nil {
log.Println(err)
}
// Encode lossless webp
if err = webp.Encode(&buf, m, &webp.Options{Lossless: true}); err != nil {
log.Println(err)
}
if err = ioutil.WriteFile("output.webp", buf.Bytes(), 0666); err != nil {
log.Println(err)
}
fmt.Println("Save output.webp ok")
}
go.mod中: module test_prj
go 1.20
require ( github.com/chai2010/webp v1.1.1 )
go run 的时候报错:
github.com/chai2010/webp
/root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:22:9: undefined: webpGetInfo /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:26:20: undefined: webpDecodeGray /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:39:20: undefined: webpDecodeRGB /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:52:20: undefined: webpDecodeRGBA /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:68:14: undefined: webpDecodeGrayToSize /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:82:14: undefined: webpDecodeRGBToSize /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:96:14: undefined: webpDecodeRGBAToSize /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:109:7: undefined: toGrayImage /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:110:14: undefined: webpEncodeGray /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:119:14: undefined: webpEncodeRGB /root/go/pkg/mod/github.com/chai2010/[email protected]/webp.go:119:14: too many errors
golang版本: go version go1.20.14 linux/amd64
我也出现了
这个问题请问下解决了吗 我也遇到了
这个问题请问下解决了吗 我也遇到了
我也出现了
CGO的环境变量被禁止了吧 go env -w CGO_ENABLED=1
it works CGO_ENABLED=1 ?
this package uses CGO to interface with the WebP C library. I have fixed this by enabling CGO:
export CGO_ENABLED=1
you may also need a C compiler