当我尝试使用内存是否正常检查运行go单元测试系统时,我会得到一条错误消息,我确信可以通过将编译器设置为CLANG来解决这个错误。
Go命令文档化在这件事上有点简短。
-msan
enable interoperation with memory sanitizer.
Supported only on linux/amd64, linux/arm64
and only with Clang/LLVM as the host C compiler.
On linux/arm64, pie build mode will be used.在过去,我使用它,我通过调用:
CC=clang go test -msan ./..然而,当我现在这样做的时候,我会发现一些错误,例如:
g++: error: unrecognized argument to -fsanitize= option: ‘memory’为了在Ubuntu 18:04下使用内存杀菌剂运行我的golang测试,我需要做什么?
我目前正在使用以下版本的工具:
$ go version
go version go1.14 linux/amd64
$ clang --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin发布于 2020-07-27 13:23:16
它需要在运行程序的Ubuntu18.04版本上支持-fsanitize=memory的LLVM版本。请尝试更新,然后再试一次。
还请注意,在Linux上,您至少需要LLVM3.8才能获得-fsanitize标志。
Go工具自动将-fsanitize=memory选项添加到CGO_CPPFLAGS标志中,这是clang为链接所要求的,这将导致您的错误。
此外,请确保同时添加CC和CXX (用于clang++)标志,以便在与C/C++互操作程序时启用Clang编译。
CC=clang CXX=clang++ go build -msan也参考了这个链接
https://go.googlesource.com/go/+/go1.7/misc/cgo/testsanitizers/test.bash (bash脚本)
(或)
https://github.com/golang/go/tree/master/misc/cgo/testsanitizers (*.go文件)
它将帮助您测试消毒液,如果他们会对您的设置是否有效。
https://stackoverflow.com/questions/63059865
复制相似问题