Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,052 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,562 people online right now. Registration is fast and FREE... Join Now!




How to combine to programs in a project

 
Reply to this topicStart new topic

How to combine to programs in a project

Pitufo
5 Aug, 2008 - 09:49 AM
Post #1

New D.I.C Head
*

Joined: 23 Jul, 2008
Posts: 25

I created a project and added two programs to it. For some reasons it doesnt want to compile...i get this...
multiple definition of main
first defined here
id returned 1 exit status
[Built Error][Pro.exe] Error 1


How can i fix it?
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: How To Combine To Programs In A Project
5 Aug, 2008 - 10:31 AM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
You probably have 2 mains, or maybe your main doesn't abide to the proper standards.

Does it look like one of the following:
int main ()
int main (int argc, char *argv[])
int main (int argc, char **argv)
ques.gif

If not, post your code and I'll take a look smile.gif

Edit:
After reading the title of your topic, I'm guessing you have two main functions.

You're gonna have to merge them, or rename one of them and call it in your actual main.
Post the code and I'll help you out smile.gif
User is offlineProfile CardPM
+Quote Post

Pitufo
RE: How To Combine To Programs In A Project
5 Aug, 2008 - 10:35 AM
Post #3

New D.I.C Head
*

Joined: 23 Jul, 2008
Posts: 25

I have a project named pro and two programs in the project

program 1

int main()

program 2

int main()

how can you merge them?

This post has been edited by Pitufo: 5 Aug, 2008 - 10:37 AM
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: How To Combine To Programs In A Project
5 Aug, 2008 - 10:58 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
I'm gonna need to see all of your code to explain it properly.

Do you want to have a menu to decide which program to run?

Or do you want to run one after the other?

Post it all, and I'll merge it for you and explain it properly smile.gif
User is offlineProfile CardPM
+Quote Post

Arttu
RE: How To Combine To Programs In A Project
5 Aug, 2008 - 11:01 AM
Post #5

New D.I.C Head
*

Joined: 4 Aug, 2008
Posts: 1


My Contributions
Maybe you have misunderstood what the "project" means.
I think that "project" is just one application, but you can divide your code into different source files. And you can't have more than one main.
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: How To Combine To Programs In A Project
5 Aug, 2008 - 11:20 AM
Post #6

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
That's right, that's why I suggested merging them.

When you have a project, it will usually consist of .cpp .h and sometimes .rc files.

One way that you could do it is to rename each main to be functions, so instead of having "main" and "main" you could have "function1" and "function2"

Then, if you put it in a menu, you could have:
cpp
#include <iostream>
using namespace std

// declare your two functions
void function1 ();
void function2 ();

int main ()
{
cout << "which function would you like to call? (1/2)";
int choice;
cin >> choice;
switch (choice)
{
case 1:
function1(); // function call
break;
case 2:
function2(); // function call
break;
}
return EXIT_SUCCESS;
}

void function1 ()
{
// function1 definition goes here
}

void function2 ()
{
// function2 definition goes here
}

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

Pitufo
RE: How To Combine To Programs In A Project
6 Aug, 2008 - 09:27 AM
Post #7

New D.I.C Head
*

Joined: 23 Jul, 2008
Posts: 25

thanks...you guys rock...
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: How To Combine To Programs In A Project
6 Aug, 2008 - 09:34 AM
Post #8

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
we I certainly do tongue.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 05:41PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month