mingw C++ won't compile j0 funciton

2019-03-05 08:42发布

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?

Sample code:

#include <cmath>


int main( int argc, char *argv[] )
{
    float test = j0( 5 );
}

Output

$ 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 );

1条回答
霸刀☆藐视天下
2楼-- · 2019-03-05 09:00

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/

You might also try -std=gnu++11 instead. See https://stackoverflow.com/a/19667112/10077

查看更多
登录 后发表回答