[Solved] c – compile main file with source files and header [closed]


You have source files card.c, deck.c, and main.c. It is reasonable to suppose that card.c and deck.c each define functions, at least one of which is called by something in main.c, else there would be no need for your header.h. Presumably, the functions named in your link errors are among those.

The command

gcc main.c

attempts to compile the code in main.c and link it to form a complete program, but it is not enough for a complete program because some of the needed functions are defined (implemented) in other source files. That’s what the linker is complaining about.

If you want to compile main.c to an object file but not link it, then you need the -c option:

gcc -c main.c

If you want to build a complete program with one run of gcc then you must specify all the needed sources:

gcc main.c deck.c card.c

In the latter case, you might also want to use the -o option to specify a name different from a.out for the executable.

solved c – compile main file with source files and header [closed]