Missing header files?

Started by
4 comments, last by jpetrie 15 years, 9 months ago
I want to output a C/C++ compiler message if one of my header files is missing, like:

#include "myheader.h"

#ifndef _MYHEADER_H_
#pragma message( "header file is missing!" )
#endif
However, it doesn't get that far. Instead I get an error message: "fatal error C1083: Cannot open include file: 'myheader.h': No such file or directory" Is it possible to do something like this? Maybe I'm looking at this problem the wrong way.
Advertisement
The line beginning with "fatal error..." is a compiler message complaining about a missing header. In C and C++, it is mandatory that the included files are accessible by the pre-processor - this is in contrast to php, for example, which makes distinction between "include" and "require". This behavior makes it very inpractical (or impossible) to automatically drive build variables based on whether a header file exists or not.

Niko Suni

Quote:Original post by Nik02
The line beginning with "fatal error..." is a compiler message complaining about a missing header. In C and C++, it is mandatory that the included files are accessible by the pre-processor - this is in contrast to php, for example, which makes distinction between "include" and "require". This behavior makes it very inpractical (or impossible) to automatically drive build variables based on whether a header file exists or not.


Thanks. I guess no luck then.

What is you goal?

I would guess that you want the include to be optional, in which case you can just use a different preprocessor define:
#ifdef USE_MYLIBRARY#include "my_library_header.h"#else// something else#endif// latervoid foo(){#ifdef USE_MYLIBRARY    MyLibrary::function();#else    // some default fallback perhaps#endif}
Quote:Original post by rip-off
What is you goal?


If somebody besides myself tries to compile my code, and gets a missing header file error message,
I was hoping to give some additional feedback as to where this header file might be located,
by inserting my own custom message in the compiler output.

Unfortunately that's not likely going to be accurate; the information you can provide is only going to be reasonable in a small number of cases so you will likely do more harm than good.

It's better to simply let the compiler inform the users that the header is missing; a user who is competent enough to be considering the compilation of third-party code should be competent enough to understand what a missing header error means.

This topic is closed to new replies.

Advertisement