I think your problem will be difficult to solve. I suspect header.h is included from the file in the include1 folder.
This means that the standard path C includes
- The directory of the source file (or the header file that includes the additional file).
- The order specified on the command line includes.
So, to fix this, we would need to (somehow) stop rule 1 from firing.
Using #include "projecta/header.h" and #include "projectb/header.h" is the usual way to achieve this if you do not want to change the source.
In your case, you want yours (included2 included).
Ways you could apply.
If the previous code (.c / .cpp files) is mutable, then make sure that you #include "include2/header.h" - which should also set up so all requirements for include1 / header.h`.
if include1/header.h has an inclusion protector ( #if ! defined( H_HEADER_H) ), then define this on the command line ( /DH_HEADER_H ), so it is not included - itβs a blow in the dark, since the file will not fulfill its purpose.
Write a text modification script (sed?) To change "header.h" to "include2 / header.h", which ensures that all occurrences in the source select your version. This is not a specification, but it can be thought of as leaving the source code unchanged, as it will be a step to compilation.
The goal of changing the order of inclusion can be achieved by creating two separate projects - one that uses include1/header.h , and the source code does not change. It then suggests include2/header.h as an interface, which is being modified in some way.
mksteve
source share