Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two files containing definition of main() Visual Studio?

I have created a project in Visual Studio 2008 Professional Edition.

This project contains one .cpp file for each assignment like this...

[-]Source Files
   \
   |-- 233.cpp
   |-- test.cpp

And each file contains definition of main().

Action:CTRL+F5

Error   1   error LNK2005: _main already defined in 233.obj test.obj
Error   2   fatal error LNK1169: one or more multiply defined symbols found 

How do I compile and see output of each file ?

Thanks.

like image 649
Pratik Deoghare Avatar asked Mar 14 '09 19:03

Pratik Deoghare


People also ask

How to search for a file in Visual Studio 2022?

Ctrl + Shift + T.

What is APstudio_ invoked?

The #ifndef APSTUDIO_INVOKED directive instructs Visual C++ to skip over Compile-Time Directives. The corresponding TEXTINCLUDE resource is: rc Copy.


2 Answers

You can't have 2 functions called main() in a single project. What you should do is change the names of the functions, and then call them from a new main() function which would function as a menu.

If you make them separate projects, you can switch which one to run with Solution Properties -> Startup Project.

like image 174
rlbond Avatar answered Sep 27 '22 23:09

rlbond


I guess in your situation your project consists of just one file. If you want to compile them separately then I suggest:

  • create individual project (CSPROJ) file per each of them
  • use command line compiler CSC to compile these files separately
  • or (as suggested) rename your current Main methods to Run methods, create a separate file named Program.cs with just the Main method and from this method call to a particular Run method (depending on which task you want to execute)
like image 44
David Pokluda Avatar answered Sep 27 '22 22:09

David Pokluda