user20842454566
user20842454566

Reputation: 115

Fatal error: No such file or directory for header file

I'm currently running Ubuntu (The latest firmware) and have a bunch of directories I've made for my c-programming. However, I’m getting an error when compiling telling me that it can't find the "file.h" header file Within my main folder "temp" the directories are as follows

temp

Then:

src bin include assets Makefile

src contains a .c file which is:

#include "file.h"

int main(void)
{
    initscr();
    noecho();
    cbreak();

    char ch;
    FILE * ptr;
    ptr = fopen("input.txt","r");

    if (ptr == NULL)
    {
        mvprintw(0,0,"Error reading from file");
        exit(1);
    }

    while( ( ch = fgetc(ptr) ) != EOF )
    mvprintw(0,0,"%c",ch);
    refresh();

    fclose(ptr);
    return 0;

}

and my include folder contains the Header file(which gives me the error) This is what file.h contains...

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ncurses.h>

I've also got a makefile as follows:

all:
        gcc -Wall -pedantic -std=c99 src/file.c assets/input.txt -o bin/runMe

And finally assets include a .txt file "input.txt" which the program is just supposed to read some characters from the text file, which is in the assets directory. I've tried using the "#include < >" notation, but that didn't seem to help. I also tried to use something along the lines of "#include "include/file.h", but as well it was to no avail.

Upvotes: 2

Views: 29584

Answers (1)

n0p
n0p

Reputation: 3496

If file.h is in temp directory, add to your command in the Makefile:

-Itemp

And in a.c:

#include <file.h>

You should use #include "file.h" when file.h is in the same directory of the file that include it.

Upvotes: 4

Related Questions