You can compile, but you cannot link.
part1.o
is using the functions you defined in your last .h
file and the implementations cannot be found. When you link your program, you need to make sure you’re linking in the object file(s) (or libraries) that contain the implementations of those functions. You’ve likely done something like:
gcc part1.c -o myapp
and so the linker doesn’t have all the pieces to the puzzle.
If you want to compile in parts, you need to:
gcc -c part1.c -o part1.o gcc -c implementations.c -o implementations.o gcc implementations.o part1.o -o myapp
Here, all the .c
files are compiled into object (.o
) files separately, and then linked together into an executable. Or you could do everything at once:
gcc part1.c implementations.c -o myapp
If the implementations are in a library (libimplementations.a
):
gcc part1.c -Lpath/to/libs -limplementations -o myapp