The problem seems to be that sayHello.c
got compiled into an object file called sayHello.obj
, and main.c
(also including all the source text from sayHello.c
), got compiled into main.obj
, and so both .obj
files got a copy of all the external symbols (like non-static
function definitions) from sayHello.c
.
Then all the object files were supposed to get "linked" together to produce the final executable program file, but the linking breaks when any external symbols appear more than once.
If you find yourself in this situation, you need to stop linking sayHello.obj
to main.obj
(and then you might not want to compile sayHello.c
by itself into its own object file at all).
If you manually control every step of the build (like you might when using the CLI of your compiler), this is often just a matter of excluding that object file from the invocation of the linker or compiler.
Since you are using Visual Studio, it's probably making a bunch of assumptions for you, like "every .c file should be compiled into its own object file, and all those object files should be linked together", and you have to find a way to circumvent or disable this assumption for sayHello.c
.
One easy and somewhat idiomatic solution might be to rename sayHello.c
into sayHello.c.inc
.