i have created a Makefile to run C program in shell script.but i get as error fatal error: addFunc.h: No such file or directory in mainProg.c page and addFunc.c page.i tried my best to solve this problem.but i didn’t get a solution.i have mentioned my code below.
mainProg.c
#include <stdio.h>
#include "/home/name/Desktop/add/addFunc.h"
int main(){
int a,b;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
printf("sum:%d\n",add(a,b));
return 0;
}
addFunc.h
int add(int a, int b)
addFunc.c
#include "/home/name/Desktop/add/addFunc.h"
int add(int a,int b){
return (a+b);
}
Makefile
Add: mainProg.c addFunc.c
gcc -o Add mainProg.c addFunc.c -I.
Solution:
You really should be cutting and pasting, because clearly the text you’ve pasted here is nothing like what you’re actually using (you have tons of syntax errors here).
However, the problem is that the compiler can’t find your header file. This can be solved in one (or both) of two ways:
First, you should use the #include <...> form only for system headers like stdio.h etc. For your personal headers, you should use the form #include "..." instead. The difference is implementation-specific but for most compilers it is that include files using <...> are never looked for in the current directory but only in system directories and directories given with -I, while include file using "..." are looked for also in the current directory.
You could also simply ask the compiler to always look in the current directory by adding the -I. option to your compile line in your makefile.