I've created three files namely test.cpp, function.h and function.cpp in a folder. test.cpp contains this code :
#include <bits/stdc++.h>
#include "function.h"
using namespace std;
int main()
{
freopen ("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);
int a,b;
cin >> a >> b;
cout << add(a,b) << endl;
return 0;
}
function.h contains this code:
#include <cstdio>
using namespace std;
int add(int a,int b);
function.cpp contains this code:
#include <cstdio>
using namespace std;
int add(int a,int b);
int add(int a,int b) {
return a+b;
}
This produces some error which says reference in add(int,int) is undefined. Here is the error message:
/tmp/ccbx3TEZ.o: In function main':
test.cpp:(.text+0x81): undefined reference to
add(int, int)'
collect2: error: ld returned 1 exit status
[Finished in 2.0s with exit code 1]
Please, suggest me what to do.