Reputation: 8206
I have a c++ file that keeps throwing errors about four files up the chain, while every other file using that #include compiles fine.
It keeps giving me this kind of stuff. I am certain the include file is fine as 1. All of the others which use this same file compile fine and 2. I looked at the file, and it is fine.
/usr/include/opal/opal/mediafmt.h:305:9: error: expected identifier before numeric constant
/usr/include/opal/opal/mediafmt.h:305:9: error: expected ‘}’ before numeric constant
/usr/include/opal/opal/mediafmt.h:305:9: error: expected unqualified-id before numeric constant
/usr/include/opal/opal/mediafmt.h:308:14: error: bit-field ‘mode’ with non-integral type
It's odd because it throws the error about 5 files up the chain:
In file included from /usr/include/opal/opal/connection.h:44:0,
from /usr/include/opal/opal/call.h:41,
from /usr/include/opal/opal/manager.h:42,
from /usr/include/opal/opal/endpoint.h:41,
from /usr/include/opal/opal/localep.h:41,
from /home/jonathan/workspace/HHPVideoServer/opal/GstEndPoint.h:12,
from /home/jonathan/workspace/HHPVideoServer/opal/opal-call-manager.h:42,
from ../gui/HHPVideoCodecGui.cc:3:
I checked to make sure I wasn't screwing up any #define s but that was the only idea I had. Is there a good approach someone can offer me on how to track this error down?
Here is the file:
http://www.opalvoip.org/docs/opal-v3_9/da/d60/mediafmt_8h-source.html
Update
Here is the struct with the troublesome line from the preprocessor. I suppose the "0L" is the trouble.
struct H245GenericInfo {
H245GenericInfo() { memset(this, 0, sizeof(*this)); }
unsigned ordinal:16;
enum Modes {
0L,
Collapsing,
NonCollapsing
} mode:3;
enum IntegerTypes {
UnsignedInt,
Unsigned32,
BooleanArray
} integerType:3;
bool excludeTCS:1;
bool excludeOLC:1;
bool excludeReqMode:1;
};
then
#define None 0L
from "/usr/include/X11/X.h" causes 0L to be substituted for None in the Modes enumeration at line 305.
from the X11 lib. The reason the other files were compiling is that they weren't also using Gtk. Does any one have a work around that doesn't involve me rewriting either of the lib files?
solution
I just put the offending #include above everything else. Thanks for the help everyone.
Upvotes: 2
Views: 971
Reputation: 263617
Assuming you're using gcc, run gcc -E your-file.c > tmpfile
. This runs just the preprocessor. The output is going to be quite voluminous, but it should help you track down the problem.
What does line 305 look like?
EDIT:
Given your update, yes, the problem is that "None" is being defined as a macro before your mediafmt.h tries to define it as an enumerator. Can you add #undef None
after including X.h and before including mediafmt.h? (If so, be sure to comment it.)
EDIT2: Rearranging the #include
directives might be a better solution -- but again, be sure to add a comment explaining the reason.
Upvotes: 6
Reputation: 34338
Since you found 0L
in place of None
it's likely you have #define None 0L
somewhere in your include chain. Either reorder the includes, like Klox suggested, so this definition happens after mediafmt.h
is included, or try and convert, undefine, or fix the offending None
definition elsewhere.
Upvotes: 2
Reputation: 966
Because you said that this include works from other files, I'm guessing that the order of your #includes may be different in the failing file. Try moving the #include for opal-call-manager.h to the top of the file.
Ideally, you would follow the answers others have posted to track down the root cause, but simply reordering the #includes may be a quick solution and will help narrow down what is conflicting.
Upvotes: 2