views:

64

answers:

3

Hi,

I'm trying to compile a third-party library, but g++ is complaining about the following line:

typedef boost::shared_ptr<MessageConsumer> MessageConsumerPtr;

The strange thing is, there is no #include directive in the file - and it is clearly supposed to be this way; there are about 60 files with the same (or very similar) issues. Clearly if there was an #include directive referencing the relevant boost header this would compile cleanly.

My question is: how can I get g++ to somehow automagically find the relevant symbol (in all instances of this issue, it is a namespace that can't be found - usually std:: or boost::) by either automatically processing the relevant header (or some other mechanism).

Thanks.

Edit

My current g++ call looks like:

g++ -fPIC -O3 -DUSING_PCH -D_REENTRANT -I/usr/include/boost -I./ -c MessageInterpreter.cpp -o MessageInterpreter.o
+2  A: 

You can use the -include command line option:

g++ -include boost/shared_ptr.hpp ...

From the man page:

-include file Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal.

R Samuel Klatchko
Thanks - that fixed it - now I have to go through and find all the 30 odd missing includes...
jwoolard
+1  A: 

Create your own wrapper .h file that includes the boost .h and then the broken .h .

Or (very fragile) ensure that you precede every use of the broken .h with boost .h .

Arkadiy
A: 

Perhaps the third-party library is designed in such a way that you should always include a certain "main" header file in order to get the dependencies right.

Otherwise, you can add #include <boost/shared_ptr.hpp> before including the third-party header file that is giving the error message.

StackedCrooked