定义的宏无法识别 [英] Defined macro not recognized
问题描述
我的Eclipse项目中有以下代码
#pragma once
#ifdef WIN32 //编译器进入这里!
#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;问题是我从编译器得到以下错误 Luzoso.hpp:22:20:错误:'M_PI'未在此范围内声明
return((float)M_PI /180.f)* deg;
我不明白这是什么问题。我使用CMake使用 ECLIPSE CDT4 - MinGW Makefiles
作为生成器构建项目。任何建议?
解决方案 WIN32
不是正确的宏。它实际上是 _WIN32
。无论哪种方式,这是由Visual Studio C ++定义的宏,但您使用 MinGW ,因此实际的宏检查 __ MINGW32 __
或(64)。这仍然是错误的做事方式,因为 MSDN 要求:
#define _USE_MATH_DEFINES // for C ++
#include< cmath>
为了访问数学常数。 MinGW已执行此操作。
I have the following code in my Eclipse project
#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;
}
Problem is that I'm getting the following error from the compiler
Luzoso.hpp:22:20: error: 'M_PI' was not declared in this scope
return ((float)M_PI/180.f) * deg;
I don't understand what the problem might be. I built the project with CMake using ECLIPSE CDT4 - MinGW Makefiles
as the generator. Any advise?
解决方案 WIN32
isn't the correct macro. It's actually _WIN32
. Either way, that's a macro defined by Visual Studio C++, but you're using MinGW so the actual macro to check for is __MINGW32__
or (64). This still is the wrong way to do things, since MSDN requires:
#define _USE_MATH_DEFINES // for C++
#include <cmath>
In order to access the math constants. MinGW already does this.
这篇关于定义的宏无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!