【问题标题】:mingw C++ won't compile j0 funcitonmingw C++ 不会编译 j0 函数
【发布时间】:2017-02-14 16:41:42
【问题描述】:

我正在尝试使用 MingW (msys2) 在 Windows 上编译一个程序,但它使用 j0 函数失败。在 Linux 上它编译没有问题。当我在编译器上使用 -std=c++11 标志时,它似乎很讨厌。我怎样才能让它正确编译并打开 -std=c++11 标志?

示例代码:

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

【问题讨论】:

    标签: windows c++11 mingw cmath


    【解决方案1】:

    显然MinGW只在__STRICT_ANSI__未定义时才定义Bessel函数,在-std=c++11指定时才定义。通过在文件顶部添加#undef __STRICT_ANSI__,我能够让您的代码在 MinGW 中编译。见https://sourceforge.net/p/mingw-w64/feature-requests/68/

    您也可以尝试使用-std=gnu++11。见https://stackoverflow.com/a/19667112/10077

    【讨论】:

    • 这是一个非常好的答案。添加 -std=gnu++11 确实很好地解决了这个问题。
    猜你喜欢
    • 2012-06-01
    • 2021-03-03
    • 2020-08-28
    • 2014-04-05
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多