Indexer workaround for partial includes [message #901906] |
Wed, 15 August 2012 00:32 |
Jay Dolan Messages: 4 Registered: August 2012 |
Junior Member |
|
|
Hi CDT community,
When I upgraded from Helios to Juno, my CDT project suddenly had thousands of unresolved symbols. After a lot of unsuccessful experimentation with the Builder, Indexer, and the Preprocessor settings in Eclipse, Google finally turned up this on the CDT wiki:
http://wiki.eclipse.org/CDT/designs/Overview_of_Parsing#Indexing
Quote:When a header file is included in a source file it is subject to any macros that have been defined at that point. Some library headers use macros in conjunction with preprocessor conditionals (#ifdefs) to partially include a header file. Sometimes such a header file is included more than once in a project, if the macros that the header depends on are different each time the header is included then different parts of the header may be included in different source files. Neither indexer will be accurate in this scenario because it will only index the header the first time it is encountered.
Bummer! The old full indexer worked beautifully for my code, which does a lot of partial includes for limiting visibility; e.g.:
foo.h
#ifndef __FOO_H__
#define __FOO__H__
void foo_public(void);
#ifdef __FOO_LOCAL_H__
void foo_private(void);
#endif
#endif
foo_local.h
#ifndef __FOO_LOCAL_H__
#define __FOO_LOCAL_H__
#include "foo.h"
#endif
Code including foo_local.h would suffer from unresolved symbols for everything conditionalized in foo.h, which is clearly incorrect, but a consequence of the new "fast" (*cough* lazy) indexer
My workaround is to provide an __ECLIPSE__ symbol via the Paths and Symbols settings, and then update all of my headers like so:
foo.h
#ifndef __FOO_H__
#define __FOO__H__
void foo_public(void);
#if defined(__FOO_LOCAL_H__) || defined(__ECLIPSE__)
void foo_private(void);
#endif
#endif
The only significant shortcoming of this approach is that Eclipse will actually resolve *more* symbols than what are really available to you, making the code assist a little busier than it should be. But it's certainly better than having thousands of unresolved symbols in your code!
FYI, my project is an open source 3D video game, Quake2world [quake2world.net]
And you can checkout the source code here if you'd like to see how I set the project files up in Eclipse/CDT:
svn://quake2world.net/quake2world/trunk
Feedback welcome! If there's a better way to do this, or if the old full indexer is scheduled to make a return, I'm all ears!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03347 seconds