我的Eclipse项目中有以下代码
#pragma once
#ifdef WIN32 // Compiler enters here !
#define M_PI 3.14159265358979323846
#else
#include <cmath>
#endif
#ifndef INFINITY
#define INFINITY FLT_MAX
#endif
inline float Radians(float deg)
{
return ((float)M_PI/180.f) * deg;
}
Run Code Online (Sandbox Code Playgroud)
问题是我从编译器得到以下错误
Luzoso.hpp:22:20: error: 'M_PI' was not declared in this scope
return ((float)M_PI/180.f) * deg;
Run Code Online (Sandbox Code Playgroud)
我不明白问题可能是什么.我使用CMake ECLIPSE CDT4 - MinGW Makefiles作为生成器构建了项目.有什么建议吗?
WIN32是不正确的宏.实际上_WIN32.无论哪种方式,这是由Visual Studio C++定义的宏,但您使用的是MinGW,因此要检查的实际宏是__MINGW32__或(64).这仍然是错误的做事方式,因为MSDN要求:
#define _USE_MATH_DEFINES // for C++
#include <cmath>
Run Code Online (Sandbox Code Playgroud)
为了访问数学常量.MinGW已经这样做了.
| 归档时间: |
|
| 查看次数: |
610 次 |
| 最近记录: |