“Multiple definition”, “first defined here” errors

The problem here is that you are including commands.c in commands.h before the function prototype. Therefore, the C pre-processor inserts the content of commands.c into commands.h before the function prototype. commands.c contains the function definition. As a result, the function definition ends up before than the function declaration causing the error. The content of commands.h … Read more

How to prevent multiple definitions in C?

You actually compile the source code of test.c twice: The first time when compiling test.c itself, The second time when compiling main.c which includes all the test.c source. What you need in your main.c in order to use the test() function is a simple declaration, not its definition. This is achieved by including a test.h … Read more