Search code examples
cvisual-studioprogram-entry-point

Main function already defined in visual studio project


I created windows console program project in visual studio, and made two c language files. Both has same source:

#include<stdio.h>

int main() {
    printf("hello");
}

When I try to compile, compiler screams about having two main()s. See below:

enter image description here

I can't understand. I thought two files in one project works separately. Am I wrong?


Solution

  • Yes, you are wrong. IIRC, the whole project is compiled and then linked to form a single executable.

    In a single executable, there can be only one main() function.