Game Programming and Development Tools

Linker Error - C++ – Mene-Mene

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Well I've gotten to work on my Classes/Functions relationships and started a little program to test it for a larger concept. I've eliminated all the errors, only to find one more, a linker error.

quote:

[Linker error] undefined reference to 'WinMain@16'
Id returned 1 exit status

Here's the code: (It's got more things than it needs for what it does, but that's because its part of a bigger scheme.


#include <iostream>
using namespace std;

// Var Space

// End Var Space

// Class Space
// Class Dec/Def Space
class Object {
public:
Object();
~Object();
// Location Mods
int ChangeX(int degree);
int ChangeY(int degree);
// End Location Mods

// Time Mods
int ChangeYear(int degree);
int ChangeMonth(int degree);
int ChangeDay(int degree);
int ChangeMinute(int degree);
int ChangeSecond(int degree);
// End Time Mods

// Output
int ReadX();
int ReadY();
int ReadYear();
int ReadMonth();
int ReadDay();
int ReadMinute();
int ReadSecond();
// End Output

protected:
// Location Var
int X;
int Y;
// End Location Var

// Time Var
int Year;
int Month;
int Day;
int Minute;
int Second;
// End Time Var
};
// Class Func Space
// Object Class Func Space
Object::Object()
{
int X = 0;
}
Object::~Object() {
// Hello
}
int Object::ChangeX(int Degree) {
X = X + Degree;
};
int Object::ChangeY(int Degree) {
Y = Y + Degree;
};
int Object::ChangeYear(int Degree) {
Year = Year + Degree;
};
int Object::ChangeMonth(int Degree) {
Month = Month + Degree;
};
int Object::ChangeDay(int Degree) {
Day = Day + Degree;
};
int Object::ChangeMinute(int Degree) {
Minute = Minute + Degree;
};
int Object::ChangeSecond(int Degree) {
Second = Second + Degree;
};

int Object::ReadX() {
cout << X;
};

int Object::ReadY() {
cout << Y;
};

int Object::ReadYear() {
cout << Year;
};

int Object::ReadMonth() {
cout << Month;
};

int Object::ReadDay() {
cout << Day;
};

int Object::ReadMinute() {
cout << Minute;
};

int Object::ReadSecond() {
cout << Second;
};

int main() {
Object Ball;
Ball.ReadX();
cout << endl;
Ball.ChangeX(5);
cout << "Incremented by 5 \n";
Ball.ReadX();
cin.get();
return 0;
};

Oh yeah, and its in Dev C++ incase its not portable.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

[This message has been edited by Mene-Mene (edited April 11, 2007).]

[This message has been edited by Mene-Mene (edited April 11, 2007).]

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Here are a few thoughts.

Try using 'main' instead of 'Main'.

That may still not work since it's looking for a WinMain. Something in your linker is telling it to create a Windows application, so it wants to see a WinMain function. I think you may just want to create a console application. Look at your linker options and figure out how to just create a console application.

Maybe try using WinMain instead of main and see what happens. But I really don't think this is what you want in your case. Also, WinMain has a different signature than WinMain.

This one is extremely unlikely, but you don't happen to have a .DEF file with WinMain defined, do you?

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
okay, I changed Main to main and it worked, but the output has me confused. It's outputting:
quote:

100

It should be out putting:

quote:

0
Incremented by 5
5

I'm confused now.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
100? There's nothing that could cause that in your code.
Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Try it for yourself.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
Well, here's what I got upon running it:


2009291924
Incremented by 5
2009291929

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
in your constructor you're defining a local "X" variable. meaning you're not initializing the instance variable to 0 so it's undefined; you'll get a random memory location

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Captain: Even yours makes more sense than mine. Yours is incremented like its supposed to, it just has a REALLY weird starting number. Mine makes 0 sense at all. What compiler are you using?

Jez:
Its not exactly local. Its a protected object specific. its initialized here:


int X;

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

[This message has been edited by Mene-Mene (edited April 11, 2007).]

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
yes it is a local variable. you have X defined in your class, but in your constructor you have "int X = 0;"
that makes a local variable in the constructor that dies when the function ends. Take away the "int" and it'll work fine (i tested it)

EDIT: when you have instance variables, ALWAYS initialize them to '0', especially if they're pointers. I prefer to do it this way:

Object::Object() : X(0), Y(0){
//...
}

[This message has been edited by jestermax (edited April 11, 2007).]

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Makes sense now, but unfortunetly I'm still getting 100.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
Are you initializing X to 0?
Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Yes, It should say at least Incremented by 5. but I'm only getting either one hundred, or one, zero, zero.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
are you using this as your constructor?:

Object::Object()
{
X = 0;
}

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Yes, I even copied yours and pasted it.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
then the only thing i can think of is that either it's an IDE issue (settings/linker) or something to do with not recompiling (clean + compile).

All i can say is that the following code works fine for me. Output :
0
increment by 5
5

#include <iostream>
using namespace std;

// Var Space

// End Var Space

// Class Space
// Class Dec/Def Space
class Object {
public:
Object();
~Object();
// Location Mods
int ChangeX(int degree);
int ChangeY(int degree);
// End Location Mods

// Time Mods
int ChangeYear(int degree);
int ChangeMonth(int degree);
int ChangeDay(int degree);
int ChangeMinute(int degree);
int ChangeSecond(int degree);
// End Time Mods

// Output
int ReadX();
int ReadY();
int ReadYear();
int ReadMonth();
int ReadDay();
int ReadMinute();
int ReadSecond();
// End Output

protected:
// Location Var
int X;
int Y;
// End Location Var

// Time Var
int Year;
int Month;
int Day;
int Minute;
int Second;
// End Time Var
};
// Class Func Space
// Object Class Func Space
Object::Object()
{
X = 0;
}
Object::~Object() {
// Hello
}
int Object::ChangeX(int Degree) {
X = X + Degree;
};
int Object::ChangeY(int Degree) {
Y = Y + Degree;
};
int Object::ChangeYear(int Degree) {
Year = Year + Degree;
};
int Object::ChangeMonth(int Degree) {
Month = Month + Degree;
};
int Object::ChangeDay(int Degree) {
Day = Day + Degree;
};
int Object::ChangeMinute(int Degree) {
Minute = Minute + Degree;
};
int Object::ChangeSecond(int Degree) {
Second = Second + Degree;
};

int Object::ReadX() {
cout << X;
};

int Object::ReadY() {
cout << Y;
};

int Object::ReadYear() {
cout << Year;
};

int Object::ReadMonth() {
cout << Month;
};

int Object::ReadDay() {
cout << Day;
};

int Object::ReadMinute() {
cout << Minute;
};

int Object::ReadSecond() {
cout << Second;
};

int main() {
Object Ball;
Ball.ReadX();
cout << endl;
Ball.ChangeX(5);
cout << "Incremented by 5 \n";
Ball.ReadX();
cin.get();
return 0;
};

possibly if it IS an IDE issue, then try creating a new project (make sure it's a console project, not a win32 one)

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

Calin

Member

Posts: 358
From: Moldova
Registered: 12-04-2006
quote:
Originally posted by Mene-Mene:
Well I've gotten to work on my Classes/Functions relationships and started a little program to test it for a larger concept. I've eliminated all the errors, only to find one more, a linker error.

Here's the code:


Oh yeah, and its in Dev C++ incase its not portable.


I would seriously consider using C# as an alternative. C# is a real alternative to C++ and in my opinion even surpasses it. If you're up for some reading you can find a list of links on the C++ vs C# subject in this GameDev theread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=417750
(4th post from the top)
I might be outnumbered by 3:1 on this issue but C# will spare you a lot of headache ( no linkage problems, he header files, simplified syntax, to name just a few). You really don't care about the 5% penalty many like to talk about. Beside that I really don't see any major advantage from using C++ (maybe except the case were you want to get a job in the gamedev industry in the next few months which I don't think is your case)

Calin

P.S. with multicore processors flooding the market, processing speed is no longer the bottleneck in software development (more so in gamedev).
------------------
a good gameplay is a right combination between performance and features.

[This message has been edited by Calin (edited April 14, 2007).]

[This message has been edited by Calin (edited April 14, 2007).]