Multiple Source Files in VC++ 2008

Error when trying to compile each file

Page 1 of 1

5 Replies - 1531 Views - Last Post: 10 November 2009 - 03:08 PM Rate Topic: -----

#1 InfiniteL00P  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 05-November 09

Multiple Source Files in VC++ 2008

Posted 09 November 2009 - 10:10 PM

Hey guys, this is bit of a noob question, but when working with VC++ 2008, how can you add several source files to a project and still be able to compile them all individually? My problem is that I am declaring the first file as the int main() but I don't know what to declare the other files so that I can compile them as well. (If I use int main() on the other files I get an error LNK2005: _main already defined in <filename>). Basically, what should I do to be able to compile them all. Also, they are not related, I am just going through exercises in a book and want to keep them organized.

Example:
#include <iostream>
using namespace std;
int main(){   
cout << "Get with the Program! \n";
return 0;
}


New, Separate File:
#include <iostream>
using namespace std;
int main(){				//What should I declare here so I can compile to test the code?
cout << "Having trouble! \n";
return 0;
}


This post has been edited by InfiniteL00P: 09 November 2009 - 10:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Multiple Source Files in VC++ 2008

#2 InfiniteL00P  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 05-November 09

Re: Multiple Source Files in VC++ 2008

Posted 09 November 2009 - 10:42 PM

Anybody understand what I'm asking? I feel like it is probably simple, but I can't find an answer on google.
Was This Post Helpful? 0
  • +
  • -

#3 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Multiple Source Files in VC++ 2008

Posted 09 November 2009 - 10:44 PM

Create separate projects. The idea of a project is that all files comprise one executable. If you want to organize several related binaries, create a solution and have multiple projects under that solution.
Was This Post Helpful? 0
  • +
  • -

#4 rs4  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 153
  • Joined: 01-February 09

Re: Multiple Source Files in VC++ 2008

Posted 09 November 2009 - 10:49 PM

As the error says you are trying to build the project with two entry points( int main() 's) . In Visual C++ you can exclude a file from a build to do this right click it (in solution explorer) and click properties under general change exclude from build from no to yes.
Was This Post Helpful? 1
  • +
  • -

#5 gronk  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 168
  • Joined: 28-October 09

Re: Multiple Source Files in VC++ 2008

Posted 10 November 2009 - 01:05 AM

I find it easier to create one project per executable. I think VS2008 does support multiple executables, DLLs etc in a single project but I haven't got a clue how. Also that way separate projects can be managed easily; once I've done with one I can delete or archive it without affecting anything else.

This might help though:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vssoln/html/f4e0a576-ccdf-4f22-a098-983f318ce43d.htm (Multi-Project Solutions)
Open Help -> Contents then paste the above into the URL box.
Was This Post Helpful? 1
  • +
  • -

#6 InfiniteL00P  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 05-November 09

Re: Multiple Source Files in VC++ 2008

Posted 10 November 2009 - 03:08 PM

Yea, I started thinking about it a bit more and realized this. Thanks for clarifying. I was thinking more in terms of just separate files like in Dev C++ or something simpler. Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1