I'm experimenting with linking and sharing header files in C; I would like to share this function, tool.c
, between many programs:
void sayHello() {
printf("Hello!");
}
...I define the function in tool.h
:
void sayHello();
It makes a lot of sense if other programs #include tool.h
so that they can all call the sayHello
function. I need to create a single program from multiple files. Here I can create an entirely different program (target) that calls the function:
#include <stdio.h>
#include "/usr/someone/somewhere/tool.h"
int main() {
sayHello();
}
Though, the linker process fails: linker command failed with exit code 1
. If you wish, download the Xcode project here.
What am I doing wrong?