I tried to search a good answer online but fail to get one I can fully understand. Suppose I have a header "add.h":
inline int add(int a, int b){ return a+b; }
A file called "adddouble.c":
#include "add.h"
int adddouble(int a, int b){ return 2*add(a,b); }
A file called "addsquare.c":
#include "add.h"
int addsquare(int a, int b){ return add(a,b)*add(a,b); }
A main file "main.c":
#include<stdio.h>
int adddouble(int, int);
int addsquare(int, int);
int main(){
printf("add double = %d\n", adddouble(10,20));
printf("add square = %d\n", addsquare(10,20));
return 0;
}
I use gcc5.2.0 to compile those files, but got: "Undefined symbols for architecture x86_64:". If I add static to inline function in add.h or add declaration "extern int add(int, int);" to "adddouble.c", it compiles successfully without errors. I am new to inline function, I don't know how to explain and understand this behaviour. thanks