-3

I have written a code that just basically add two numbers. file is the self made header file named xoxo.h

extern int add(int r,int m);

This is my second file that contains the function defination of the function add.The name is run.c

#include "xoxo.h"
int add (int i,int f) {
  return (i+f);
}

This is my main file tester.c

#include "xoxo.h"
#include <stdio.h>
void main() {
  printf("%d",add(1,2));
}

The error is shown as

PS C:\Users\HOME\Desktop\New folder> gcc tester.c C:\Users\HOME\AppData\Local\Temp\ccBwWXFk.o:tester.c:(.text+0x1e): undefined reference to `add' collect2.exe: error: ld returned 1 exit status

plz help

Daniel Trugman
  • 8,186
  • 20
  • 41
Soumyadip
  • 7
  • 3

1 Answers1

2

When you compile the application, you need to provide run.c as well, otherwise the application cannot find the implementation of add.

Run gcc tester.c run.c instead.

Daniel Trugman
  • 8,186
  • 20
  • 41