Sign in to follow this  
rosewell

Missing header files?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

// later
void foo()
{
#ifdef USE_MYLIBRARY
MyLibrary::function();
#else
// some default fallback perhaps
#endif
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this