Public Group

This topic is 3692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to output a C/C++ compiler message if one of my header files is missing, like:
#include "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 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 on other sites
Quote:
 Original post by Nik02The 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 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// latervoid foo(){#ifdef USE_MYLIBRARY    MyLibrary::function();#else    // some default fallback perhaps#endif}

##### Share on other sites
Quote:
 Original post by rip-offWhat 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 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.

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 20
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632145
• Total Posts
3004381

×