我想在Golang中调用C代码:</ p>

  /  / #cgo CFLAGS:-I / usr / include / c ++ / 8.1.1 / bits 
// #cgo CXXFLAGS:-std = gnu ++ 11
// #include“ c ++ 0x_warning.h”
import “ C”
</ code> </ pre>

但出现错误:</ p>

  ./ main.go:5包含的文件中:

/ usr / include / c ++ / 8.1.1 / bits / c ++ 0x_warning.h:32:2:错误:#error此文件需要ISO C ++ 2011标准的编译器和库支持。 必须使用-std = c ++ 11或-std = gnu ++ 11编译器选项启用此支持。
</ code> </ pre>

因此cgo不使用CXXFLAGS。 我尝试了 -std = c ++ 11 </ code>,但它也不起作用。 我做错了什么?</ p>

  $ go version 
go version go1.10.3 linux / amd64
</ code> </ pre>
</ div>



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



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>.

Csdn user default icon