问题
在编译我的项目时,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's Sourceforge上找到的。下面是上面的内容:
这是由一些平台的粗鲁造成的,这些平台使用一些生硬的#定义来破坏名称空间。更准确地说,Win32 API包括#定义“错误”和“调试”。由于预处理器不知道C++命名作用域,这将导致保留单词错误并在任何地方进行调试。特别是,这与log4cpp::Prioritiy::ERROR和log4cpp::优先级::DEBUG相冲突。后两个名字来自log4j,所以它们不是我们自己编出来的。他们Win32作者不应该粗鲁地通过预处理器声明这些通用名称。还有更好的选择: 如果他们使用它作为整数常量,则使用语言构造来声明它。“enum{ERROR=1};”或“ERROR=1;” 会做得很好。使用一个不太通用的名称(如WIN32API_ERROR )可以减少命名冲突的可能性,如果他们将命名冲突用作条件编译的标志,请使用‘#defined调试’和‘#如果定义了(调试)’。在这种情况下,预处理器只需将源代码中出现的所有“DEBUG”替换为“DEBUG”,这实际上使一切保持不变。 当然,正确的解决办法是,如果冒犯的一方使用上述方法之一,但我们可能需要等待一段时间才能真正做到这一点。作为另一种选择,log4cpp可以解决这些#定义。通过在#之前#定义LOG4CPP_FIX_ERROR_COLLISION 1(包括任何log4cpp头文件)和#之后(包括所有平台头)来启用解决方案代码。对于Win32平台,这个#define已经包含在log4cpp/config-win32.h中。 一旦log4cpp被更新为log4j 1.2API,我们就可以通过为日志级别采用新的名称来解决这个问题。
上下文
问题是,我不应该改变源代码。我只能修改编译配置文件(这个项目使用Apache构建器、build.xml文件和bash脚本)。
我对这个项目非常陌生,我不能向以前的开发人员寻求帮助。
问题
以前有人遇到过这个错误吗?除了修改源代码和定义源代码之外,还有其他可能的解决办法吗?我的环境变量是原因吗?
我会继续我的搜索,但是任何洞察力都是有用的。谢谢!
发布于 2018-04-23 15:01:36
正如文档中所述,您需要定义LOG4CPP_FIX_ERROR_COLLISION。如果不允许修改任何源,则应该可以在build.xml中这样做:
<define name="LOG4CPP_FIX_ERROR_COLLISION" value="1" />https://stackoverflow.com/questions/49984042
复制相似问题