Monday, September 26, 2011

Subtle compiler error due to circular dependency


Spent 2 hours debugging a compiler error. It keeps complaining about
error: expected ';' before '{' token
error: expected specifier-qualifier-list before 'type_name'
Turns out it's due to a circular dependency in header files, even with include guards...

foo.h
#include "bar.h"
bar.h
#include "foo.h"
 Fix is easy, just move the shared dependency out into a new header file.

foo.h
#include "shared.h"
bar.h
#include "shared.h"
shared.h
//Shared definition here

No comments:

Post a Comment