检测到'DEBUG'的 Log4cpp 命名冲突。

Log4cpp Naming Collision for 'DEBUG' detected.

本文关键字:冲突 DEBUG 检测 Log4cpp      更新时间:2023-10-16

问题

编译我的项目时,log4cpp文件出错。错误如下:/usr/include/log4cpp/Priority.hh:49:2: erreur: #error Naming collision for 'DEBUG' detected. Please read the FAQ for a workaround.

文件

此错误引用的文件是与Log4cpp一起安装的标头。是的。错误在的第49、78和109行

/*
* Priority.hh
*
* Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
* Copyright 2000, Bastiaan Bakker. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#ifndef _LOG4CPP_PRIORITY_HH
#define _LOG4CPP_PRIORITY_HH
#include <log4cpp/Portability.hh>
#include <string>
#include <stdexcept>
/*
* Optionally work around rudeness in windows.h on Win32.
*/
#ifdef ERROR
#ifdef LOG4CPP_FIX_ERROR_COLLISION
namespace log4cpp {
static const int _tmpERRORValue = ERROR;
}
#undef ERROR
static const int ERROR = log4cpp::_tmpERRORValue;
#define ERROR ERROR
#else  // LOG4CPP_FIX_ERROR_COLLISION
#error Naming collision for 'ERROR' detected. Please read the FAQ for a 
workaround. 
#endif // LOG4CPP_FIX_ERROR_COLLISION 
#endif // ERROR
/*
* Other Win32 rudeness in EDK.h
*/
#ifdef DEBUG
#ifdef LOG4CPP_FIX_ERROR_COLLISION
#undef DEBUG
#define DEBUG DEBUG
#else  // LOG4CPP_FIX_ERROR_COLLISION
#error Naming collision for 'DEBUG' detected. Please read the FAQ for a 
workaround. 
#endif // LOG4CPP_FIX_ERROR_COLLISION 
#endif // DEBUG
namespace log4cpp {
/**
* The Priority class provides importance levels with which one
* can categorize log messages.
**/
class LOG4CPP_EXPORT Priority {
public:
static const int MESSAGE_SIZE; // = 8;
/**
* Predefined Levels of Priorities. These correspond to the
* priority levels used by syslog(3).
**/
typedef enum {EMERG  = 0, 
FATAL  = 0,
ALERT  = 100,
CRIT   = 200,
ERROR  = 300, 
WARN   = 400,
NOTICE = 500,
INFO   = 600,
DEBUG  = 700,
NOTSET = 800
} PriorityLevel;
/**
* The type of Priority Values
**/
typedef int Value;
/**
* Returns the name of the given priority value.
* Currently, if the value is not one of the PriorityLevel values,
* the method returns the name of the largest priority smaller 
* the given value.
* @param priority the numeric value of the priority.
* @returns a string representing the name of the priority.
**/
static const std::string& getPriorityName(int priority) throw();
/**
* Returns the value of the given priority name. 
* This can be either one of EMERG ... NOTSET or a 
* decimal string representation of the value, e.g. '700' for DEBUG.
* @param priorityName the string containing the the of the priority
* @return the value corresponding with the priority name
* @throw std::invalid_argument if the priorityName does not 
* correspond with a known Priority name or a number
**/
static Value getPriorityValue(const std::string& priorityName)
throw(std::invalid_argument);
};
}
#endif // _LOG4CPP_PRIORITY_HH

研究

我在log4cpp的Sourceforge上找到了唯一一个提到这个问题的常见问题解答。上面写着:

这是由一些平台的粗鲁造成的,这些平台破坏了带有一些钝#定义的命名空间。更确切地说,Win32 API包括"ERROR"answers"DEBUG"的#定义。由于预处理器是不知道C++命名作用域,这导致保留单词ERROR到处乱丢垃圾。尤其是与log4cpp::优先级:错误和log4cpp::优先级:调试。后者两个名字来自log4j,所以它们不是我们编造的我们自己Win32作者不应该粗鲁地宣称通过预处理器的通用名称。还有更好的备选方案:

If they use it as an integer constant, declare it using a language construct. Either 'enum {ERROR=1};' or 'static const int ERROR=1;'

会做得很好。使用不太通用的名称,如WIN32API_ERROR,以降低命名冲突的可能性如果他们将其用作条件编译的标志,请使用"#define DEBUG DEBUG"answers"#if defined(DEBUG)"。在这种情况下预处理器只需替换源代码带有"DEBUG",实际上保留了所有内容。

当然,如果违规方使用上述方法之一,但我们可能需要等待一段时间这是真的发生了。作为一种替代方案,log4cpp可以解决问题这些#定义。通过执行#define来启用解决方法代码#之前的LOG4CPP_FIX_ERROR_COLLISION 1,包括任何LOG4CPP标头文件和#之后,包括所有平台标头。对于Win32平台这个#define已经包含在log4cpp/config-win32.h中。

一旦log4cpp更新到log4j 1.2 API,我们就可以摆脱通过采用日志级别的新名称来解决此问题。

上下文

问题是,我不应该更改源代码。我只能修改编译配置文件(这个项目使用ApacheAnt构建器、build.xml文件和bash脚本)。

我对这个项目很陌生,不能向以前的开发人员寻求帮助。

问题

以前有人遇到过这个错误吗?除了更改源代码及其定义之外,还有其他可能的解决方法吗?我的环境变量是原因吗?

我将继续我的搜索,但任何见解都是有用的。谢谢

正如文档中所说,您需要定义LOG4CPP_FIX_ERROR_COLLISION。如果您不被允许修改任何源,那么您应该能够在build.xml中进行修改:

<define name="LOG4CPP_FIX_ERROR_COLLISION" value="1" />