dongmang3961 2018-06-25 18:46
浏览 390

cgo不包含CXXFLAGS

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
  • 写回答

1条回答

  • douguangxiang0363 2018-06-29 21:51
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配