1

I'm trying to compile (under Linux) a project that was developed under Windows. The project has a header file named features.h. Linux has a system header file with the same name. gcc takes the system header file and ignore the project's header file.

I know I can specify the path to the header file in the #include line to force the compiler to find the project's header file. But the source files shouldn't be modified.

Is there a way to fix this problem without touching the source files (e.g., by a compiler flag)?

Salahuddin
  • 1,617
  • 3
  • 23
  • 37
  • Read documentation of [GCC](http://gcc.gnu.org/) and of [GNU cpp](https://gcc.gnu.org/onlinedocs/cpp/). `gcc`, `make`, Linux are [free software](https://www.gnu.org/philosophy/free-sw.en.html), you are allowed to study their source code and improve it. You could be interested by [GNU autoconf](https://www.gnu.org/software/autoconf/). Read the chapter about [Invoking GCC](https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html) – Basile Starynkevitch Feb 05 '21 at 10:15
  • But the simplest approach (and probably the easiest to understand) is to rename *your* `features.h` as something else. For a project Foo, try `foo-features.h`. In a few months, that change would make your code more readable. So ask permission to your manager to make such a change – Basile Starynkevitch Feb 05 '21 at 10:20
  • I tried this approach and it worked. But then I knew that the code itself should not be modified (for some compatibility reasons). – Salahuddin Feb 05 '21 at 10:23
  • Look at [Bismon](http://github.com/bstarynk/bismon/), [Frama-C](http://frama-c.com/) and [this draft report](http://starynkevitch.net/Basile/bismon-doc.pdf). See also [DECODER](https://www.decoder-project.eu/) – Basile Starynkevitch Feb 05 '21 at 10:30
  • 4
    @BasileStarynkevitch I know you posted a comment and not an answer, but suggesting the OP read the documentation of half a dozen compilers, operating systems, and other software plus maybe modifying their source code, is *way* overkill for the OP's problem. – JBentley Feb 05 '21 at 11:15
  • 1
    @Salahuddin The solution (in relation to not wanting to modify the code for compatiblity reasons) is to have different includes depending on the OS. On Windows, you'd include features.h. On Linux you'd do something different. See for example [here](https://stackoverflow.com/questions/16551042/c-platform-specific-includes). Needing software to have slightly different behaviour for different platforms is a well understood (and solved) problem. – JBentley Feb 05 '21 at 11:18
  • You can also see [this question](https://stackoverflow.com/questions/344317/where-does-gcc-look-for-c-and-c-header-files) for details on where GCC looks for header files (and in what order), as well as how to override that order. I'm confused what you mean by "gcc takes the system header file and ignore the project's header file". If you have a header file with the same name in the same folder as the including file, gcc should include that first before it looks anywhere else. – JBentley Feb 05 '21 at 11:23
  • Can you tell us if the output of CFLAGS `-xc -E -v` does show something in relation to these files? – Vroomfondel Feb 05 '21 at 13:02

0 Answers0