Library include paths with same header name

后端 未结 5 1556
慢半拍i
慢半拍i 2020-12-30 03:42

What is the best method to include a file that has same name in another folder from additional include directories?

Example:

lib1/include/foo.h
lib2/         


        
5条回答
  •  梦谈多话
    2020-12-30 04:35

    You can just do this:

    #include "lib1/include/foo.h"
    #include "lib2/include/foo.h"
    

    and make sure that the parent directories of both lib1 and lib2 are in your search path for includes (but not the actual include subdirectories themselves).

    Note that if both headers use the same symbol as an include guard then this method will not work - you would need to undefine the conflicting symbol between the two includes:

    #include "lib1/include/foo.h"
    #undef FOO_H
    #include "lib2/include/foo.h"
    

提交回复
热议问题