On my ubuntu system, I write the code that using activemq-cpp 3.6.0 and mman.h and there is a tricky compile error.
I write a very simple code to verify this problem:
#include <sys/mman.h>
#include <activemq/core/ActiveMQConnection.h>
int main(int argc, char** argv)
{
return 0;
}
And here is the compile error message:
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,
If I put the "mman.h" after "activemq/core/ActiveMQConnection.h", it will be OK. Anyone have the same problem?
======UPDATE ON 2015/1/7===========================================
I have a further investigation on this issue. In "bits/mmap.h":
# define MAP_TYPE 0x0f /* Mask for type of mapping. */
In "activemq/util/PrimitiveValueNode.h":
enum PrimitiveType {
...,
MAP_TYPE = 11,
...
}
Here is the conflict. So the "PrimitiveValueNode.h" must be included before "mman.h".
I think this is the typical scenario to show why we SHOULD NOT use #define in C/C++ code.
This is most probably related to conflict of some defines or global declaration. If something was defined in mman.h and same string/name was used later in second header it may cause such error. Changing the order of include helps because of the way how compilation unit is builded - problematic define is later. I had situation like this many times, but with different headers.