Can the C preprocessor be used to tell if a file exists?

后端 未结 9 1737
眼角桃花
眼角桃花 2020-11-30 22:21

I have a very large codebase (read: thousands of modules) that has code shared across numerous projects that all run on different operating systems with different C++ compil

9条回答
  •  感动是毒
    2020-11-30 22:57

    Create a special folder for missing headers, and make that folder to be searched last
    (that is compliler specific - last item in "INCLUDES" environment variable, something like that)

    Then if some header1.h can be missing, create in that folder a stub

    header1.h:

    #define header1_is_missing
    

    Now you can always write

    #include 
    #ifdef header1_is_missing
    
       // there is no header1.h 
    
    #endif
    

提交回复
热议问题