Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

borok

macrumors newbie
Original poster
Feb 5, 2009
6
0
Hi the program is mostly done, i am trying to compile it and thats when i have problems; I only get a blank screen after i run it.

thats the program:
Code:
#include "exo1.h"

#include <iostream>
using namespace std;
#ifndef NONVIRTUELLE_H
#define NONVIRTUELLE_H

class NonVirtuelle {
	int x;
public:
    void a() const {}
    int b() const { return 1; }
};
#endif

#ifndef UNEVIRTUELLE_H
#define UNEVIRTUELLE_H
class UneVirtuelle {
    int x;
public:
    virtual void a() const {}
    int b() const { return 1; }
};
#endif

#ifndef DEUXVIRTUELLES_H
#define DEUXVIRTUELLES_H 
class DeuxVirtuelles {
    int x;
public:
    virtual void a() const {}
    virtual int b() const { return 1; }
};
#endif

int main1() {
    cout << "La taille d'un entier: " << sizeof(int) << endl;
    cout << "La taille de NonVirtuelle: " << sizeof(NonVirtuelle) << endl;
    cout << "La taille d'un pointeur void: " << sizeof(void*) << endl;
    cout << "La taille de UneVirtuelle: " << sizeof(UneVirtuelle) << endl;
    cout << "La taille de DeuxVirtuelles: " << sizeof(DeuxVirtuelles) << endl;
    return 0;
}
I would like to know whats the problem and how to correct it.

if anyone can post me the results of that program, i would appreciate it.
Thanks for help.
 

Tygernoot

macrumors member
Jul 3, 2003
69
22
Brussels
Is main1() your application's main function?

Then it should be named main() instead of main1(). Otherwise you should call main1() from your main() function.

Hope this helps.
 

borok

macrumors newbie
Original poster
Feb 5, 2009
6
0
When i do put main() i get an error:
Command /Developer/usr/bin/g++ failed with exit code 1
I found a thread online, and read bout changing main to main1.

I am new in Mac, first time using Xcode.

Thank You
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
When i do put main() i get an error:
Command /Developer/usr/bin/g++ failed with exit code 1

Can you print more of the error? That just says that gcc failed. But before that there should be much more info about why it failed.

I found a thread online, and read bout changing main to main1.

That doesn't sound like very good advice.
 

borok

macrumors newbie
Original poster
Feb 5, 2009
6
0
that's all the error msg:

Building target “tp1” of project “tp1” with configuration “Debug”


Checking Dependencies

Ld /Users/alisobh/Desktop/tp1/build/Debug/tp1.app/Contents/MacOS/tp1 normal i386
cd /Users/alisobh/Desktop/tp1
setenv MACOSX_DEPLOYMENT_TARGET 10.5
/Developer/usr/bin/g++-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -L/Users/alisobh/Desktop/tp1/build/Debug -F/Users/alisobh/Desktop/tp1/build/Debug -filelist /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/tp1.LinkFileList -mmacosx-version-min=10.5 -framework Carbon -o /Users/alisobh/Desktop/tp1/build/Debug/tp1.app/Contents/MacOS/tp1
ld: duplicate symbol _main in /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/exo1.o and /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/main.o
collect2: ld returned 1 exit status


thanks
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
So here is the key:

Code:
ld: duplicate symbol _main in /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/exo1.o and /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/main.o

So it looks like you have another object file called exo1.o which also has a main() function.
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
Well, so, after you compile this program you are writing, everything will be linked together, and then when you run it the main() function will be called.

So depending on what you are trying to do, you need to decide which main() function should be the main function for the app. Then if you need to call the other function, you can always do so from within main().

But you can't have two main() functions.

So which main() do you want is the question? Decide that and then rename the other one.
 

borok

macrumors newbie
Original poster
Feb 5, 2009
6
0
that's the problem, i only have 1 main(), which is the main fonction that i know about!
exo.h is the header...when i created a new project it opened exo1.h and exo1.cpp.
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
that's the problem, i only have 1 main(), which is the main fonction that i know about!
exo.h is the header...when i created a new project it opened exo1.h and exo1.cpp.

And you checked exo1.cpp and you're sure there is no main() there?
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
that's the problem, i only have 1 main(), which is the main fonction that i know about!
exo.h is the header...when i created a new project it opened exo1.h and exo1.cpp.

You have only one main () function and it looks like you have no idea where it is. You also have a function named main1 (), but it doesn't matter one bit what it does, because it never gets called.

Well, if you read those error messages carefully, the linker told you exactly where those two functions named main () were. Here's the error message again:

ld: duplicate symbol _main in /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/exo1.o and /Users/alisobh/Desktop/tp1/build/tp1.build/Debug/tp1.build/Objects-normal/i386/main.o
 

borok

macrumors newbie
Original poster
Feb 5, 2009
6
0
the whole program is in the first thread i posted. the only difference now is that i corrected main1() to main().
when its main1() the program succeeds but it opens a blank screen w/o anything.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
the whole program is in the first thread i posted. the only difference now is that i corrected main1() to main().
when its main1() the program succeeds but it opens a blank screen w/o anything.

No, it isn't. You posted what you THINK is the whole program. You didn't post the whole program. Read the bloody error message again. I even marked in bold exactly where the second main () function is; you just have to read it.

In XCode, press Command-Zero to show the project overview, then reveal "Implementation Files". Then think very very hard about what you see there.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.