[cfe-dev] Suggestion for improving #include error message

Justin Johansson procode at adam.com.au
Thu Oct 29 04:51:01 PDT 2009


Greetings Clang people,

My name is Justin and have joined this list about 5 minutes ago.

This afternoon I downloaded LLVM 2.6 and clang as separate bundles.

I'm pleased to say that the build on Linux/Ubuntu went very smoothly.
The documentation explained quite well how to place clang under the LLVM
root/tools directory and that a build of LLVM would pick up tools/clang
and build clang as well.

Great; it worked as advertised and this is a really good start compared
to some other open source projects that have borrowed my time :-)

Better still my first "hello, clang" .c compile worked just as well 
though after
first complaining (and rightfully so) about my not #including stdio.h 
(which I
deliberately initially omitted just to see what error message might 
surface.)

So after #including stdio.h, clang hello.c faithfully compiled and 
linked the
classical hello program to a working executable.

Oh, there was another compiler complaint regarding my initial void 
main() declaring
should be returning an int and I thought "Fair enough, thanks for the 
very user
friendly error message."

include <stdio.h>

int main()
{
    printf( "Hello, clang\n");
    return 0;
}

So with this as a starting point and reading about how clang desires to 
produce
friendlier error messages compared to gcc, I wondered what might 
transpire if the
#include file could not be found (and come to think of it, at this point 
I had
absolutely no idea what directory, out of my many c/c++ compiler 
installations,
that clang was actually picking stdio.h up from.)

Accordingly I changed the #include to this:

include <stdioz.h>

and got this

~/workspace/llvm-2.6/jj $ clang hello.c
hello.c:1:10: fatal error: 'stdioz.h' file not found
#include <stdioz.h>

which was quite to be expected but this now prompts my suggestion that 
it would
be even nicer if clang told me which directories it searched for the unfound
include file "stdioz.h", i.e. if it displayed the include path.

I know this is a really small issue but me thinks little improvements like
this can be really helpful to newcomers, of which I am one.

What do you think?

Regards

Justin Johansson  (c/c++ veteran; clang newbie).





More information about the cfe-dev mailing list