How to tell g++ compiler where to search for include files?

后端 未结 4 1737
难免孤独
难免孤独 2020-12-01 23:38

In a \"working directory\" I have a lot of *.cpp and *.h files that #include each other and files from subdirectories.

For example:

#inc         


        
4条回答
  •  情话喂你
    2020-12-02 00:06

    Read The Fine Manual

    It's there for everyone to read. You even have a choice of what to use (I'd go with the first):

    -Idir
    

    Add the directory dir to the head of the list of directories to be searched for header files. This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. However, you should not use this option to add directories that contain vendor-supplied system header files (use -isystem for that). If you use more than one -I option, the directories are scanned in left-to-right order; the standard system directories come after.

    If a standard system include directory, or a directory specified with -isystem, is also specified with -I, the -I option is ignored. The directory is still searched but as a system directory at its normal position in the system include chain. This is to ensure that GCC's procedure to fix buggy system headers and the ordering for the include_next directive are not inadvertently changed. If you really need to change the search order for system directories, use the -nostdinc and/or -isystem options.

    -iquotedir
    

    Add the directory dir to the head of the list of directories to be searched for header files only for the case of #include "file"; they are not searched for #include , otherwise just like -I.

提交回复
热议问题