-2

I'm pretty new to coding in c, but I have sample code that I imported into the eclipse console. However, when I go to build the project I run into various errors. All of these errors are because a code that I have in one folder is not able to access code in another folder. For example my main function is located in project>src>main.c but is not able to access the project.h file located in project>headers>project.h. I am also no able to access code directly above in the hierarchy either. For example, my project>src>compiler>comp.h is not able to access project>src>calc.h file. Is there a way I can instruct the code to find it? I have tried using #include "../src/calc.h" in my comp.h file but I still get the error message "No such file or directory." Any suggestions would be very helpful.

Jesse
  • 1
  • Possible duplicate of [How do I add a directory to C header include path?](https://stackoverflow.com/questions/4825652/how-do-i-add-a-directory-to-c-header-include-path) – Chris Turner Oct 27 '17 at 13:19

2 Answers2

0

Header files can be tricky to include, it depends where you are compiling.

Try to compile like this :

gcc -o myBinary <your .c files> -I./your/path/to.h (it will link your .h files at the compilation state)

drumz
  • 65
  • 7
0

The best idea would be to create a Makefile and configure it to make your header files works in every files of your project, have a look at How to create a Makefile.

Addict
  • 93
  • 8