Is there a preprocessor that can check if a header exists before trying to #include it?
Not as far as I know. There might be some compiler extension that does this, but nothing standard.
This kind of thing is generally handled by the build system and/or compilation flags. Technically speaking, there could be a way to obtain information from the compiler whether a header file exists or not, but that would be crude at best and not very useful. Generally, you use a build system (such as cmake, autoconf, Boost.Build, etc.) to do things like checking if a header file exists, finding the path to a header file that you're not sure where it could be, finding alternative paths / libraries to use, and doing things like disabling the compilations of some source files under some conditions, and so on.. This is what a build system (or build configuration system) is useful for, so, that's where you should be doing that kind of thing. Once you determine what optional headers exist, you would typically set certain defines (
#define) that you can test in your code, for example:
#if defined(HAVE_FOUND_OPENCV_HDR) #include <cv.h> #include <cvaux.h> #elif defined(HAVE_FOUND_FREEIMAGE_HDR) #include <FreeImage.h> #else #error "No appropriate image library installed on the system! Options are OpenCV or FreeImage." #endif
Another mechanism for this kind of thing is to assess the nature of the platform you are compiling for by using pre-processor definitions that are defined by the compiler. These defines generally can be used to infer which compiler is being used, what OS it is compiling for, and on what architecture (type of processor) it is compiling for. These can be used to "select" the right system-specific headers to include.
Would you might telling us exactly in what context you need this "try-include" mechanism? It will help us to help you find an appropriate solution.
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
Here is the sample output that I ...
Hello All ...
Iam Getting An Error With try to excecute the stored procedure .
I have Have Sql database , the stored procedure like so :
USE [MPRS] GO /****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...