Help!

I’m trying to get started in opengl, I tried compiling a simple program, but I get
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/gl.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Dunno whats going on. Help?

Some people should never be allowed near a compiler.

Try doing a search. This topic has been covered many times before.

Latrans,
Your response was uncalled for. Or maybe you were born knowing these things.

Myotis,
Thanks for the suggestion, but I am not sure what should I use to search for this problem. It is very confusing for me.

you created a windows appication, and created at void main() function, but the compiler expects a int WinMain(…), try creating a console application and moving your code there or replace void main() with int WinMain(…), though you would have to look up the parameters

I agree with Latrans.

The Parameter is void
so go:

void main(void)
{
}

Originally posted by Latrans:
Some people should never be allowed near a compiler.

I thoroughly disagree with Latrans. I’ve been working with openGL for about two years now and with C++ alot longer. You do not wake up with this information one moring. It is blood and tears at the start then it gets much easier.

This sort of elitist attitude pisses me off. Latrans, you are a bit of a tube!

Chowe,
Thanks for your help. But now I have a different problem. I get the error

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

I agree that it takes some time to learn to program. And even longer to learn to program well. But so many questions here are questions on how to program, not questions on OpenGL. If only people would learn to program before they learn to program with OpenGL, their life would be so much simpler. People can hurt themselves trying to run before they can walk.

Latrans,
I took a full semester of C++ in high school, so I do know how to program. I don’t think this is a normal programming error.

Some people in this thread remind me of that SNL scetch:
“Nick Burns, the company’s computer guy”

replace "int main() or void main() … "

with
"
int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
"

then add
"
int main()
{
return WinMain(GetModuleHnadle(),0,NULL,1);
}

"

Procyon,

  1. Ignore the jerkoffs

  2. Are you using GLUT or AUX? If you are, then you need to tell the compiler to create a console app.

  3. If you are not using GLUT or AUX, you need to learn how to basic windows programming (creating a WinMain, and windows.) This can take a considerable amount of time, so I would suggest trying GLUT or AUX to start.

  4. Good day

Thanks. I figured out my first problem. It was very stupid. I was using Main instead of main. I didn’t think that it would make a difference, but it did.

Now I have another problem, though. I have a struct like this:
struct Bug
{
float posX, posY, posZ;
};

And a function like this:

Bug* CreateRandomBugs(int bugCount)
{
Bug bugs[bugCount];

for (int c=0;c<bugCount;c++)
{
	bugs[c].posX = rand() % 100;
	bugs[c].posY = rand() % 100;
	bugs[c].posZ = rand() % 100;
}

return bugs;

}

When I try to compile, I get these errors
Compiling…
firstGL.cpp
f: emp\firstGL\firstGL.cpp(61) : error C2057: expected constant expression
f: emp\firstGL\firstGL.cpp(61) : error C2466: cannot allocate an array of constant size 0
f: emp\firstGL\firstGL.cpp(61) : error C2133: ‘bugs’ : unknown size
f: emp\firstGL\firstGL.cpp(65) : error C2065: ‘rand’ : undeclared identifier
f: emp\firstGL\firstGL.cpp(70) : warning C4172: returning address of local variable or temporary
Error executing cl.exe.

firstGL.exe - 4 error(s), 1 warning(s)

Please help me, I am about to pull out all my hair!

It might be helpful for you to get a good book on C/C++ before attempting to do much OpenGL. If you are struggling with the mechanics of the language at the same time you’re struggling with the mechanics of OpenGL, you’ll just end up giving yourself major headaches.

I guess your one semester of C++ didn’t teach you much about how memory is used, eh?

you will need to use either new or malloc() to allocate memory dynamically, if you have no idea what I am talking about I recommend brushing up on your c++ before attempting to use OpenGL

This line

Bug bugs[bugCount];

is wrong.

You cannot create a static array with anything other than a constant or a define.

Try dynamically allocating…
ie
Bug* bugs;
bugs=new Bug[bugcount];

but be sure to delete the array after you use it.

delete []bugs;

As myotis said, you should have a good c or c++ book nearby, or check out some c websites. Learning both c and opengl at the same time could be a bit confusing.


Jeremy

Thanks. My function is now this:

Bug* CreateRandomBugs(int bugCount)
{
Bug* bugs = new Bug[bugCount];

for (int c=0;c<bugCount;c++)
{
bugs[c].posX = rand() % 100;
bugs[c].posY = rand() % 100;
bugs[c].posZ = rand() % 100;
}

delete []bugs;

return bugs;
}

I still get the error:
f: emp\firstGL\firstGL.cpp(65) : error C2065: ‘rand’ : undeclared identifier

About books. I have a book, but I am too lazy to read it.