在我的 ubuntu 系统上,我编写了使用 activemq-cpp 3.6.0 和 mman.h 的代码,并且存在一个棘手的编译错误。
我写了一个非常简单的代码来验证这个问题:
#include <sys/mman.h>
#include <activemq/core/ActiveMQConnection.h>
int main(int argc, char** argv)
{
return 0;
}
这是编译错误消息:
g++ -c -O2 -D_INTEL686 -D_LINUX -I. -I.. -I/home/matt/devspace/trading-apps/../trading-dependency/activemq-cpp/include/activemq-cpp-3.6.0 -I/home/matt/devspace/trading-apps/../trading-dependency/apr/include/apr-1 mqtest.cpp -o mqtest.o
In file included from /usr/include/x86_64-linux-gnu/sys/mman.h:41:0,
from mqtest.cpp:2:
/home/matt/devspace/trading-apps/../trading-dependency/activemq-cpp/include/activemq-cpp-3.6.0/activemq/util/PrimitiveValueNode.h:56:13: error: expected identifier before numeric constant
MAP_TYPE = 11,
如果我把“mman.h”放在“activemq/core/ActiveMQConnection.h”之后,就可以了。有人有同样的问题吗?
======2015/1/7 更新===================================== ======
我对这个问题有进一步的调查。在“位/mmap.h”中:
# define MAP_TYPE 0x0f /* Mask for type of mapping. */
在“activemq/util/PrimitiveValueNode.h”中:
enum PrimitiveType {
...,
MAP_TYPE = 11,
...
}
这里是冲突。所以“PrimitiveValueNode.h”必须包含在“mman.h”之前。
我认为这是说明为什么我们不应该在 C/C++ 代码中使用 #define 的典型场景。