Library include paths with same header name

后端 未结 5 1547
慢半拍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:30

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

    Is fine as long as this is the actual relative path to those headers and the include guards are different. For example, if both foo.h use

    #ifndef _foo_h_
    

    then this will give you something you dont want (it will only include one, not both and which one depends on the order of execution).

提交回复
热议问题