Search code examples
cincludeconditional-compilation

MACRO of library with path to avoid including a library twice in C?


How i can use #ifndef with a library like this #include "../log/name.h" to insert only once a library in a project with multiple source and header files.


Solution

  • The header guards that's something like must have as it prevents processing it more than in one place. But if you really have to use this library header file. I would advise creating a kind of wrapper header.

    #ifndef LOG_NAME_H_
    #define LOG_NAME_H_
    #include "../log/name.h"
    #endif
    

    It will be not preprocessed and reopened twice. You can try to pull request the library for missing header guard too.