我想在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发布于 2018-06-29 21:51:47
请参考以下这样的问题:Difference between CPPFLAGS and CXXFLAGS in GNU Make,以确定您在程序上下文中真正需要哪些标志。
如果您正在调用纯C代码(而不是C++代码),我认为您不需要CXX_FLAGS
CPPFLAGS应该是C PreProcessor的标志;CXXFLAGS是C++编译器的标志。
您可能还需要检查您的go env。如果您确实需要此标志,可以尝试使用env CGO_CXXFLAGS="-std=c++11" go build <YOUR_CODE>编译程序。
https://stackoverflow.com/questions/51030039
复制相似问题