c++11 - cgo 不包含 CXXFLAGS

标签 c++11 go cgo

我想在 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/

相关文章:

c++ - 对于不可复制类型的范围循环,是否可能?

c++ - 错误 : conversion from 'const char [10]' to non-scalar type 'std::fstream {aka std::basic_fstream<char>}' requested

go - go中的[] int {}和[] int有什么区别? [复制]

json - 将 json 值解码到 []byte 中,有时字符串可能会被转义 json

c - 直接C指针转换

go - 为什么 mustSendSIGSEGV() 会继续打印,而 syscall.Kill(pid, syscall.SIGSEGV) 只打印一次

garbage-collection - 有没有一种安全的方法可以使用 CGo 从 C 代码中保留对 Go 变量的引用?

c++ - 为什么非静态数据成员引用不是变量?

c++ - 类(class)成员重新排序

windows - Golang、net.TCPConn、SetReadTimeout?