I created a new C/C++ project via File > New Project > C/C++ > C/C++ Application.
However, under the Source Files folder, only 1 source file with main is allowed.
Is there any way to include more than 1 main source file in the Source Files folder ?
Or do I have to create a new project for each source file ?
In contrast, for each Java project, there can be many .java files in it. I am trying to find the same functionality for C/C++ applications.
Thanks.
For the same project you could have many source files *.c and *.h and others
But for the same project you could have only one main() function in all of the source files
Example:
Code architecture:
.
└── source_folder
├── file1.c
├── file2.c
└── main.c
file1.c
#include <stdio.h>
void printfile1()
{
printf("this is the file1.c\n");
}
file2.c
#include <stdio.h>
void printfile2()
{
printf("this is the file2.c\n");
}
main.c
#include <stdio.h>
void printfile1(); //prototype definition
void printfile2(); //prototype definition
int main()
{
printfile1();
printfile2();
}
you can have many source files of course (.c or .cpp .cu or else extensions/ simply add new source file) but only one main() function since this is the entry point to your program
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With