问题描述
我正在尝试使用MingW(msys2)在Windows上编译程序,但使用j0函数失败.在Linux上,编译没有问题.当我在编译器上使用-std = c ++ 11标志时,似乎很讨厌.如何使它正确编译并打开-std = c ++ 11标志?
I'm trying to compile a program on Windows using MingW (msys2) and it fails with the j0 function. On Linux it compiles no problem. It seems to hate when I use the -std=c++11 flag on the compiler. How can I get this to compile properly and with the -std=c++11 flag on?
示例代码:
#include <cmath>
int main( int argc, char *argv[] )
{
float test = j0( 5 );
}
输出
$ g++ -std=c++11 test.cpp -o test
test.cpp: In function 'int main(int, char**)':
test.cpp:6:21: error: 'j0' was not declared in this scope
float test = j0( 5 );
推荐答案
显然,MinGW仅在未定义__STRICT_ANSI__
时才定义Bessel函数,并且在指定-std=c++11
时才定义.通过在文件顶部添加#undef __STRICT_ANSI__
,我能够使您的代码在MinGW中进行编译.参见 https://sourceforge.net/p/mingw-w64/feature- requests/68/
Apparently, MinGW defines the Bessel functions only when __STRICT_ANSI__
is not defined, and it is defined when -std=c++11
is specified. I was able to get your code to compile in MinGW by adding #undef __STRICT_ANSI__
at the top of the file. See https://sourceforge.net/p/mingw-w64/feature-requests/68/
您也可以尝试使用-std=gnu++11
.参见 https://stackoverflow.com/a/19667112/10077
You might also try -std=gnu++11
instead. See https://stackoverflow.com/a/19667112/10077
这篇关于mingw C ++无法编译j0函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!