0

My project is organised in a folder

myproj/
       src/
           main.c
       inc/
           main.h
       makefile

I have in my C files

 #include <main.h>

and in my makefile i have

INCLUDE = /inc
SOURCE = src/

compile:
    $(CC) -I$(INCLUDE) $(CFLAGS) $(SRCPATH)main.c -o myapp $(LIBS)

myapp: 
    $(CC) -I$(INCLUDE) $(FLG_LIB) -o myapp main.c  

but i get - fatal error: No such file or directory.

i also tried "main.h", but of no use.

madD7
  • 823
  • 10
  • 23
  • 2
    `#include "../inc/main.h"`? – Gopi Jan 29 '15 at 08:43
  • 1
    maybe this is silly, but maybe a mismatch between `SOURCE` and `SRCPATH`? – Sourav Ghosh Jan 29 '15 at 08:45
  • Just to understand the difference between `#include <...>` and `#include "..."`, you may look at [here](http://stackoverflow.com/a/21594/4384927) – Chostakovitch Jan 29 '15 at 08:46
  • Take a look at [this](http://stackoverflow.com/questions/231229/how-to-generate-a-makefile-with-source-in-sub-directories-using-just-one-makefil) – LPs Jan 29 '15 at 08:50
  • `#include ` suggests that the compiler/linker should look for this file in the library path, while `#include "main.h"` suggests it should look in your local source code. So always use the latter form for your own files. – Lundin Jan 29 '15 at 09:58

1 Answers1

3

try it again by changing 'INCLUDE=/inc' to 'INCLUDE=inc/' (notice:trim the blank character ' ' before and after the '=').

BTW,Using #include "" instead of #include <> in your case,because the first usage let the compiler find the header file firstly from local path then from the system path,the latter one(with <>) is the opposite.

Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
Chine Gary
  • 123
  • 1
  • 8