cgcccommand-linecompiler-errorsc-header

How To Include Header Files In C


I don't know how to include my own header files in my source file.

I declare addition in my header file(myhead.h):

int addition(int a, int b);

In the source file I define it(myhead.c):

int addition(int a, int b){
     return a+b;
}

In the third source file I include the header file and use addition(processSimulator.c):

#include "myhead.h"
#include <stdio.h>
int main(){
     printf("Compiled %d\n", addition(3,5));
}

It gives me this error


Solution

  • You need to add myhead.c file to gcc arguments gcc processSimulator.c my head.c