mingw C++ won't compile j0 funciton

坚强是说给别人听的谎言 提交于 2020-01-22 02:41:07

问题


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:


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



来源:https://stackoverflow.com/questions/42231558/mingw-c-wont-compile-j0-funciton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!