[haiku-3rdparty-dev] Re: Order of includes important?

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Tue, 26 Jan 2010 19:13:43 +0100

On 2010-01-26 at 18:39:57 [+0100], Humdinger <humdingerb@xxxxxxxxxxxxxx> 
wrote:
> 
> I apologize if this kind of newbie question is off-topic for this list.
> I'm dabbling with c++ and my first small app. In fact, it's already
> finished (at least I'm quite satisfied with it's current state).
> Unfortunately, while trying to clean up the source a bit, I moved a few
> #includes from a .cpp file to its .h and sorted them alphabetically.
> Since then it doesn't compile anymore... :(
> 
> I get this error (using Paladin; DarkWyrm already investigated and it's
> not Paladin's fault):
> 
> In file included from /boot/develop/headers/posix/pthread.h:9,
>                  from /boot/develop/headers/os/kernel/OS.h:10,
>                  from /boot/develop/headers/os/kernel/image.h:9,
>                  from /boot/develop/headers/os/support/Archivable.h:9,
>                  from /boot/develop/headers/os/interface/MenuItem.h:9,
>                  from /HiQ-Data/projects/QuickLaunch/QLListItem.h:12,
>                  from /HiQ-Data/projects/QuickLaunch/QLListItem.cpp:9:
> /boot/develop/headers/posix/sched.h:10: error: expected constructor,
> destructor, or type conversion before 'extern'
> 
> The line 10 in sched.h is quite inconspicuous: extern "C" {
> 
> Does anyone have any idea what could be wrong here? (This is a gcc4
> hybrid build, BTW.)

The error message suggests that the parser thinks it is in a class context, 
i.e. something like this:

class A {
#include <OS.h>
};

You might just have missed a closing brace in the header included before or 
something like that. In case of weird errors like this I usually recommend 
to have a look at the preprocessed source code. If Paladin gives you the 
gcc command line it executes, you can copy it into the terminal, replace 
the "-c" by "-E" and change the name of the output file (the one after 
"-o"). The preprocessed source is what the compiler actually sees after the 
preprocessor has resolved includes and #ifdefs, removed comments, and 
replaced macros. It contains marker lines (starting with "#") that give the 
original file and line number of the following lines. Just find the 
offending line in the preprocessed source and look backward for the cause 
of the problem. If it is indeed an unbalanced brace, your editor might help 
with the matching (at least Pe can).

CU, Ingo

Other related posts: