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

后端 未结 9 1724
眼角桃花
眼角桃花 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:58

    You could have a pre-build step run that generates an include file that contains a list of #defines that represent the names of the files existing in the current directory:

    #define EXISTS_FILE1_C
    #define EXISTS_FILE1_H
    #define EXISTS_FILE2_C
    

    Then, include that file from within your source code, and then your source can test the EXISTS_* defines to see whether a file exists or not.

提交回复
热议问题