Search code examples
compilationcompiler-errorsansi-c

Including custom header files (ANSI C)


I have made some header files and placed them in the same folder as the main program, but the compilation command gcc -ansi -Wall *.c cannot find those files. Do I have to include the full directory path of the header files or am I doing something else wrong?


Solution

  • First of all you have to include the header files into the relevant C-files if you haven't already done so as such:

    #include "path/to/file.h"
    

    You also have to tell the compiler to compile the .h-files so if your .h-files are in the same foder as you .c-files and you want to include all the present .h-files your compiler command would look like this:

    gcc -ansi -Wall *.h *.c