Link C Files
Let lib.c
be library file containing some util function.
lib.c #
#include <stdio.h>
void callLibrary() {
printf("hello from library code!\n");
}
To call callLibrary
from the main file main.c
, do it like this.
main.c #
#include "lib.h"
int main(int argc, char **argv) {
callLibrary();
}
Compile #
To compile and run…
$ gcc -Wall -Werror -o main main.c lib.c
Run #
$ ./main
hello from library code!