Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many main() can be there in a project containing multiple files ?

Status
Not open for further replies.

chandana

Programmer
Oct 2, 2001
2
US
I am working on a project involving directory structure and in each directory I have interdependent files with one file having the main function.I have three such directories.I am using a "make" file to compile all of them and come up with an .exe
My question is
1. Is it okey to do so?
2. Will the compiler understand what I am trying to do
3. If so what is the explanation for compiler not getting confused.
 
I did not understand the question 100%. Anyway, U should have only one main() for a project othewise in the compile time itself you will get error messages.

Compiling mutilple files using make will work perfectly even using make file for building multiple files is a better option.

Maniraja S
 
Thank for your prompt reply
I will try to explain it little more. I have three directories A,B,C with couple of files in each of those.A has one file with a main function so do the others too ie B and C. Say A creates certain Environment,B monitors and C Analizes that is why there are three different directories.I want to write an Executable so that all the three things happen incertain fashion.For that I want a make file so that it compiles and run these three program simultaneously.

Thank you
 
you can not do it this way.
If you can not put all of them in one main() (why by the way?) you have to compile three exe programs, then call them in batch file with three calls to created exe files or create 4-th C program that will call three others within its own main.

But really I don't see why you can not put them in one main. It doesn't mater where files are in different directories or in the same. If you like to keep everithing in different directories create another directory with one single file with main() function. Rename all other main() to main1(), main3(), main3() and placed call to them in this new main(). Don't forget add includes:
#include "../dir1/file_main1.c
#include "../dir2/file_main2.c
#include "../dir3/file_main3.c
or better skip full path and use -I ../dir1 option in makefile.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top