For the purpose of learning I want to have a project with multiple source files and each has it's own main function. How it is possible to achieve this?
What I'm trying to do is to have all my C files in the same project and selectively compile those I'm currently working on. Or better yet, supply the name of the file as an argument to the program so it can execute it:
For instance in my main.c I'd like to have (where sample*_main functions are in different files):
int main(int argc, char ** argv) {
if (argc > 0) {
if (strstr(argv[0], "sample1")) return sample1_main(argc, argv);
else if (strstr(argv[0], "sample2")) return sample2_main(argc, argv);
// etc...
}
printf("Not sure what I should run.\n");
return -1;
}
Then execute the program like so: main.exe sample1
The issue I'm having is "multiple definition of" error when compiling such type of project, when some of functions share names between sample*.c files.
sample1_mainotherwise asmain