how to include header file for each file compiled via bazel

  bazel, c++

I have a project that I’m building using bazel. My application references another bazel repository as a dependency, in its BUILD file, let’s call this @dep. I cannot make any changes to the code in @dep, but I need to override a C macro defined in one of the header files in @dep.

I thought about using the compiler option -D to define the symbol defined at the top of the header file I want to replace, which contains the C macro, and then using -include to include a different header file with my macro, for all files in @dep which are being compiled via bazel. But in cc_binary, there is no option for -include, and copt = [] will only work for the target being compiled and not for its dependencies.

I came across this post but unfortunately the solution was not posted – How to specify preprocessor includes in Bazel? (-include common_header.h)

Source: Windows Questions C++

LEAVE A COMMENT