Reputation: 119
I want to call C code in Golang:
// #cgo CFLAGS: -I/usr/include/c++/8.1.1/bits
// #cgo CXXFLAGS: -std=gnu++11
// #include "c++0x_warning.h"
import "C"
but get error:
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.
So cgo doesn't use CXXFLAGS. I tried -std=c++11
and it doesn't work too. What I do wrong?
$ go version
go version go1.10.3 linux/amd64
Upvotes: 1
Views: 2661
Reputation: 618
Please refer to the following SO question: Difference between CPPFLAGS and CXXFLAGS in GNU Make to figure out which flags you really need in the context of your program.
If you are calling pure C code (and not C++ code), I don't think you will need CXX_FLAGS
:
CPPFLAGS
are supposed to be flags for the C PreProcessor;CXXFLAGS
are flags for the C++ compiler.
You might also want to check your go env
. If you really need this flag, you can try to compile your program using env CGO_CXXFLAGS="-std=c++11" go build <YOUR_CODE>
.
Upvotes: 1