Click here to Skip to main content
15,561,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OK, I'll try my best to describe "the issue "

I have a common_include.h header . As title suggest I try to keep ALL project #include files in it . This header file is in folder /src and all the headers under this parent folder works / are being included just fine.

I have added another folder /RPI , on same level as folder /src and added a test
class under this folder.

Now how do I physically add the new class header to my common_include header?

PS
Would you kindly add verbal (in English) descriptions to your solution.

Such as "#include ../../FILE "

"include FILE located two levels DOWN (?) / UP (?) from parent folder ..."

I am really not sure if my verbal description is correct, and not really care if this example is wrong.

BUT understanding the syntax is part of my problem.

What I have tried:

I have tried to add this to my common_header file

#include "../TEST_CLASS.h "

but it did not work.
Posted
Updated 23-Sep-21 8:58am

1 solution

Typically, you would use the -I flag to the compiler, e.g.
gcc -I /src/include foo.c
This tells the compiler (actually the c-pre-processor, but we'll let that slide, since the c-pre-processor rarely gets called by itself...) to search /src/include for any files that #included using the double-quote (#include "some_heaeder.h" conventtion.

The #include mechanism does know how to follow relative path names, but note that the path is then relative to the source file, not the location you are compiling from. So if your tree looks like
src
├── include
│   └── myinclude.h
└── project
    └── project.c
then an include like #include "../include/myinclude.h" looks for an include file that is "up one and down into include" from the location of project.c
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900