[英]How to use C++17 features in an Oct file
I'm trying to use std::optional
(a C++17 feature) in a Oct file for GNU Octave. 我正在尝试在GNU Octave的Oct文件中使用
std::optional
(C ++ 17功能)。 I have upgraded to g++ version 9.1.0 and set linux environment vars 'CC' and 'CXX' to /usr/bin/gcc
and /usr/bin/g++
respectively. 我已经升级到g ++版本9.1.0,并将linux环境vars“ CC”和“ CXX”分别设置为
/usr/bin/gcc
和/usr/bin/g++
。 Running getenv
on these variables from within Octave shows that the correct compiler is set. 在Octave中对这些变量运行
getenv
表示已设置正确的编译器。 However, when running `mkoctfile', I get the following error: 但是,当运行`mkoctfile'时,出现以下错误:
oct_interface.cpp: In function ‘octave_value_list Fmibc(const octave_value_list&, int)’:
oct_interface.cpp:863:10: error: ‘optional’ is not a member of ‘std’
863 | std::optional<double> dub_opt = {};
| ^~~~~~~~
oct_interface.cpp:863:10: note: ‘std::optional’ is only available from C++17 onwards
oct_interface.cpp:863:19: error: expected primary-expression before ‘double’
863 | std::optional<double> dub_opt = {};
| ^~~~~~
warning: mkoctfile: building exited with failure status
As pointed out in the comments, the appropriate flag must be passed to the compiler in order to use C++17 features. 如注释中指出的那样,必须将适当的标志传递给编译器才能使用C ++ 17功能。 So, a more precise question might be how to configure
mkoctfile
to pass the -std=c++17
flag to the compiler. 因此,一个更精确的问题可能是如何配置
mkoctfile
以将-std=c++17
标志传递给编译器。
The problem is that the C++17 flag is not being passed to the compiler, as is pointed out in a comment by Human-Compiler. 问题是,正如Human-Compiler的注释中指出的那样,C ++ 17标志没有传递给编译器。 Compiler flags can be passed in two ways: as part of the call to the Oct-file utility, ie
mkoctfile -std=c++17
, or by setting an Octave environment variable, ie setenv("CXXFLAGS", "-std=c++17")
可以通过两种方式传递编译器标志:作为对Oct-file实用程序的调用的一部分,即
mkoctfile -std=c++17
,或者通过设置Octave环境变量,即setenv("CXXFLAGS", "-std=c++17")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.