I am trying to compile a C program on my MacBook Pro, so far the files I have look something like this:
main.c
#include <stdio.h>
#include "blah.h"
int main(int argc, char *argv[])
{
//do stuff
return 0;
}
blah.h
extern void method1()
extern void method2()
extern void method3()
blah.c
#include <stdio.h>
#include <stdlib.h>
#include "blah.h"
void method1()
{
//do stuff
}
void method2()
{
//do stuff
}
void method3()
{
//do stuff
}
However, when I try to compile, I get an error like:
$ gcc main.c -o main
Undefined symbols for architecture x86_64:
"_method1", referenced from:
_main in ccVPIYad.o
"_method2", referenced from:
_main in ccVPIYad.o
"_method3", referenced from:
_main in ccVPIYad.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I think this is because Mac compiler adds an underscore in front of every function name, but I'm not sure how to fix this. I've tried changing blah.h
to this:
extern void method1() asm ("create_list");
extern void method2() asm ("print");
extern void method3() asm ("insert_front");
but it is not fixing the problem.