Mik*_*tti 0 windows mingw cmath c++11
我正在尝试使用MingW(msys2)在Windows上编译程序,但使用j0函数失败。在Linux上,编译没有问题。当我在编译器上使用-std = c ++ 11标志时,似乎很讨厌。如何使它正确编译并打开-std = c ++ 11标志?
样例代码:
#include <cmath>
int main( int argc, char *argv[] )
{
float test = j0( 5 );
}
Run Code Online (Sandbox Code Playgroud)
输出量
$ 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 );
Run Code Online (Sandbox Code Playgroud)
显然,MinGW仅在__STRICT_ANSI__未定义时定义Bessel函数,并且在-std=c++11指定时定义它。通过#undef __STRICT_ANSI__在文件顶部添加,我能够使您的代码在MinGW中进行编译。参见https://sourceforge.net/p/mingw-w64/feature-requests/68/
您也可以尝试-std=gnu++11代替。参见/sf/answers/1376697871/