Wednesday, February 6, 2013

Compilation Error on inet-2.1.0 32/64 bit compat of MACAddress.h MACAddress.cc

  After I updated my OMNeT++ from 4.0 to 4.2.2, I also tried to update the inet to the newest version 2.1.0. According to the INSTALL file, I run the make command. I got the following errors:

linklayer/contract/MACAddress.h line 60: error: integer constant is too large for ‘long’ type
linklayer/contract/MACAddress.h line 120: error: integer constant is too large for ‘long’ type
linklayer/contract/MACAddress.h line 125: error: integer constant is too large for ‘long’ type

I found the following post by EZ.
https://groups.google.com/forum/#!msg/omnetpp/JF_BbiqQIWg/9wgJWoezgoEJ

Compilation Warning on inet-1.99.4 32/64 bit compat of MACAddress.h
1 post by 1 author in omnetpp
I have just moved to inet-1.99.4-development-03d5d15-src.tgz
I am running on Ubuntu i686:
2.6.35-32-generic #67-Ubuntu SMP Mon Mar 5 19:35:26 UTC 2012 i686 GNU/Linux

I get the warnings:
linklayer/contract/MACAddress.h:59: warning: integer constant is too large for ‘unsigned long’ type
linklayer/contract/MACAddress.h:119: warning: integer constant is too large for ‘unsigned long’ type
linklayer/contract/MACAddress.h:124: warning: integer constant is too large for ‘unsigned long’ type

It is clearly caused by the fact long int on my machine is 32bit...

AFAIK there is no "standard" way to write portable code that will know if the long int is 64bit or 32bit.
So I am not sure what to propose here. 
I think a best fix should go into OMNET configure script itself (could be coded as a simple test 
program that checks the sizeof(long int)). That would probably add -DIS64BIT or similar.

Meanwhile (for linux) we can simply add the following code to linklayer/contract/MACAddress.h:
#if defined(_WORDSIZE) && __WORDSIZE == 64 
#   define MAC_ADDRESS_MASK 0x0000ffffffffffffUL
#else
#   define MAC_ADDRESS_MASK 0x0000ffffffffffffULL
#endif
So I  opened file /src/linklayer/contract/MACAddress.h
In the head there is this line:
#define MAC_ADDRESS_MASK 0xffffffffffffL
I changed it to:
#if defined(_WORDSIZE) && __WORDSIZE == 64
#   define MAC_ADDRESS_MASK 0x0000ffffffffffffUL
#else
#   define MAC_ADDRESS_MASK 0x0000ffffffffffffULL
#endif

Run make command again, I got one similar error:
linklayer/contract/MACAddress.cc line 137: error: integer constant is too large for ‘long’ type
In file /src/linklayer/contract/MACAddress.cc line 137,
uint64 intAddr = 0x0AAA00000000L + (autoAddressCtr & 0xffffffffL);
I changed it to:
uint64 intAddr = 0x0AAA00000000ULL + (autoAddressCtr & 0xffffffffULL);

Run make again, and compile inet-2.1.0 successfully.

No comments:

Post a Comment