所需库中相同#define宏的多个定义 [英] Multiple Definitions of Same #define Macro in Required Libraries

查看:358
本文介绍了所需库中相同#define宏的多个定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我包括的两个库在各自的.h文件中共享一个宏的相同定义。

  #定义MAX<一些值> //文件中MAX的第一个定义
#define MAX< some other value> //不同文件中的MAX的第二个定义

并在编译中得到

  ... / httpd.h:43:1:警告: MAX重新定义了

  ... / opencv2 / core / types_c.h:272:1:警告:这是先前定义的位置

我已经检查每个标头,并使用#include防护措施。标记)?

解决方案

这种情况的唯一坏处是对 MAX 在您的代码中(如果有)。如果没有,在两个 #include 之间添加一个 #undef MAX 可能是最快的解决方法。如果您确实依赖于 MAX ,则可能需要找出哪一个(我想这是最后一个:-)并做一些适当的事情。 / p>

Two of the libraries I am including share the same definition of a macro in each of their respective .h files.

#define MAX <some value>       //first definition of MAX in a file
#define MAX <some other value> //second definition of MAX in a *different* file

and in compilation I get

.../httpd.h:43:1: warning: "MAX" redefined

and

.../opencv2/core/types_c.h:272:1: warning: this is the location of the previous definition

I've checked each of these headers, and they have the #include guards.

What is the best way to fix this error (failing that, suppress the warning with a different -W flag)?

解决方案

The only bad part about this situation is dependencies on MAX in your code, if any. If you don't have any, adding an #undef MAX between the two #includes is probably the fastest fix. If you do have dependencies on MAX you might need to figure out which one (I guess it's the last :-) and do something appropriate.

这篇关于所需库中相同#define宏的多个定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆