Is there a way to substitute for header files in the same directory as a source file? #4700
Unanswered
RobertCurtin-eaton
asked this question in
Community Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all, I acknowledge that this is a bit of an XY problem. I'm open to alternative ideas.
Our goal
We have a file structure looking something like this:
We want to write a test suite for
file1.c
that includes a mocked or faked version offile2.h
while still compilingfile1.c
in place.By default, header files in the current directory have priority over anything else included, so this initially seems impossible using
gcc
.Constraints
Context
What have we tried?
Using -I- has a stated side effect:
This works… for CMAKE_CXX_STANDARD 11 and 14. Unfortunately, we have teams using later versions and would like to stay up to date.
Later versions (17+) throw an error:
I'm not 100% sure, but it seems to me like
glue_memory_defs.h
is expectingexecution_defs.h
to be visible because it's in the same directory. I assume-I-
is blocking this from happening. I wasn't able to find anything in the gcc list of new language features that indicated why this would have changed between versions, though.Alternative solutions
We have an approach that involves copying files to a temporary directory, but this has the side effect of debugging / warnings / errors all pointing to the temporary files rather than the actual files, which is annoying for developers.
Don't you need the actual
file2.h
when you testfile2.c
?Currently we're generating each test suite as an individual executable. This allows us to compile the actual
file2.c
in when it's being tested, but use a mock version when we're testingfile1.c
. If there's another approach that can get us to this point without modifying source code, we're open to it.Beta Was this translation helpful? Give feedback.
All reactions