Visual C++ 2010 doesn't compile

every time i try to compile the program, a pop-up window says
"Unable to start program 'C:\Users\asampath\Documents\Visual Studio 2010\WORKSPACE\Debug\WORKSPACE.exe'

the build error message is

218 compare.obj : error LNK2005: _main already defined in 217 1 to 4.obj
1>C:\Users\Akshay\Documents\Visual Studio 2010\Projects\WORKSPACE\Debug\WORKSPACE.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

my program runs if the file is the first file in a project, but after opening a second file, nothing compiles, and the same error message is returned.

I used to use Dev C++, and this problem never occurred there, but it keeps happening with Visual.
Thank you.
have you got more than one function called main ??
my program runs if the file is the first file in a project,


roughly speaking, 1 project = 1 program.

It sounds like you are trying to add multiple programs to a single project, which isn't how it works. guestgulkan is right on the money, you have multiple main()s because you have multiple programs. When you try to run the program, it doesn't know which program you're trying to run.

If you want to make a separate program, you need to put it in a separate project.

Note that you can have multiple projects in one "solution", but that's a bit overcomplicated for now.
thank you! that should work.
my only question is, what do i do if i have to compile many files, like for school?
Well don't get your terms crossed.

a "file" is a single document that contains text. Typically a cpp file or an h file.

a "project" is a group of one or more files which are all built together to form a single program. It is not at all uncommon for a single project to consist of many files.

a "solution" is a group of one or more projects which can be bundled together for convenience.


So if you have multiple assignments, it's likely that each assignment should be its own project. If you want to compile all of them at once, then you can put all the projects into a single solution. Or you can have each project in its own solution and compile them separately.
Wow! thank you guys, I am having the exact same issue and my work around has been to go to each .cpp file and rename the main header to something like int chapter1 (), int chapter2 () etc or to remove that file from the project.

But now I understand. However creating a separate project as Disch suggested seems like one will end up with a lot of project before the class is over.

Thanks
Topic archived. No new replies allowed.