我正在尝试运行/构建一个使用 vips 的 GoLang 包。当我尝试编译程序时出现此错误:
go build gopkg.in/h2non/bimg.v1: pkg-config --cflags: -Xpreprocessor 中的无效标志
这是我的规范:
macOS Mojave Version 10.14.3
vips Version 8.7.4
go Version 1.11.5 darwin/amd64
我阅读了一些添加 CGOALLOWEDFLAGS 的问题,我也尝试过但没有成功。
最佳答案
CFLAGS
是提供给 C 编译器的额外标志。 (常用于make,参见:https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html)
gopkg.in/h2non/bimg.v1/vips.go使用 pkg-config
生成额外的标志。它有 -Xpreprocessor
标志,这是 CGo 不允许的(在撰写本文时默认情况下)。
For security reasons, only a limited set of flags are allowed, notably
-D
,-I
, and-l
. To allow additional flags, setCGO_CFLAGS_ALLOW
to a regular expression matching the new flags. To disallow flags that would otherwise be allowed, setCGO_CFLAGS_DISALLOW
to a regular expression matching arguments that must be disallowed. In both cases the regular expression must match a full argument: to allow-mfoo=bar
, useCGO_CFLAGS_ALLOW='-mfoo.*'
, not justCGO_CFLAGS_ALLOW='-mfoo'
. (See: https://golang.org/cmd/cgo/)
要允许-Xpreprocessor
,您可以设置CGO_CFLAGS_ALLOW=-Xpreprocessor
。
例如:
CGO_CFLAGS_ALLOW=-Xpreprocessor go vet ./...
关于macos - 从 go 构建 vips 库的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54755571/