我想在 Golang 中调用 C 代码:
// #cgo CFLAGS: -I/usr/include/c++/8.1.1/bits
// #cgo CXXFLAGS: -std=gnu++11
// #include "c++0x_warning.h"
import "C"
但出现错误:
In file included from ./main.go:5:
/usr/include/c++/8.1.1/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
所以cgo不使用CXXFLAGS。我试过 -std=c++11
但它也不起作用。我做错了什么?
$ go version
go version go1.10.3 linux/amd64
最佳答案
请引用以下SO问题:Difference between CPPFLAGS and CXXFLAGS in GNU Make找出您在程序上下文中真正需要的标志。
如果您正在调用纯 C 代码(而不是 C++ 代码),我认为您不需要 CXX_FLAGS
:
CPPFLAGS
are supposed to be flags for the C PreProcessor;CXXFLAGS
are flags for the C++ compiler.
您可能还想查看您的 go env
.如果你真的需要这个标志,你可以尝试使用 env CGO_CXXFLAGS="-std=c++11" go build <YOUR_CODE>
来编译你的程序。 .
关于c++11 - cgo 不包含 CXXFLAGS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51030039/