I have a C file which contains multiple functions. The example structure of mymain.c
is as follows:
#include "myheader.h"
int main(int argc, char *argv[]) {
int var1;
struct var2;
func1(var1, &var2);
if(condition)
func2(var1);
else
calc(var1, &var2);
return 0;
}
static void func1(int var1, struct *var2){
// do something
}
static void func2(int var1){
// do something
}
char * func3(char * c){
// do something
}
static void calc(int var1, struct *var2){
int myvar = 5;
char mystring[100]="....";
func1(var1, var2);
func3(mystring);
func2(myvar);
}
I want to move the calc()
and func3(char *c)
to a separate C file. Following the answers here I moved the two functions to a calc.c
file, created a calc.h
file with the calc()
signature and did a #include "calc.h"
in mymain.c
file. Also included "calc.h"
in calc.c
.
The structure of calc.c
is now:
#include "myheader.h"
#include "calc.h"
char * func3(char * c){
// do something
}
void calc(int var1, struct *var2){
int myvar = 5;
char mystring[100]="....";
func1(var1, var2);
func3(mystring);
func2(myvar);
}
When I try and build it with NetBeans it shows the following error:
In function `main':
mymain.c:(.text+0x238): undefined reference to `calc'
collect2: error: ld returned 1 exit status
Makefile:426: recipe for target 'mymain' failed
make[2]: *** [mymain] Error 1
Makefile:504: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
Makefile:393: recipe for target 'all' failed
make: *** [all] Error 2
What is going wrong here?