PDA

View Full Version : problem with first program



mikau
03-20-2006, 12:34 PM
I had trouble understanding how to get openGL so I bought a book with a disk to learn. Since getting interested in game programming, i've gone through 4 math texts but have struggled to get through one C++ book. :-( I think its because in math I can do the problems and check my answers, but C++ all I can do is read, I can't practice. I got OpenGl in hopes that I can learn to make some very simple programs and get some practice using C++. I wrote some pretty complex programs in game maker but the game maker language affords me no real programming practice.

Anyways, like I said I know very little and really don't know what I'm doing at this point, this makes asking questions kind of difficult, as well as understanding the answers. So please don't assume I know anything. I'm trying to practice so I can learn.

Anyways, I popped in the Cd and downloaded all sorts of header files, gl, glu, glaux, all kinds of wierd stuff. If I open one it opens on my borland C++ builderX ide.

Anyways, I went in my borland "include" files and found gl.h, glu.h, and glaux.h so I think all the files have been instlled properly.

So I started reading the book and typed in the first program listed to see if it was working. The book didn't tell me where to enter it so I figred do it in my borland ide. Is that what I'm supposed to do?

Anyways here is the program:




#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

{

return 0;

}
It won't compile. Error: unresolved external '_main' referenced from C:\CBUILDERX\LIB\COX32.OBJ

I rechecked the program for typo's many times but I think its all correct. Actually the original program printed a message, I removed that part when it wouldn't work to see if that was the problem, but appearantly its WinMain(). Any idea?

jide
03-20-2006, 02:48 PM
You need to include the windows library to your linker if I'm correct. (I really don't remember how Windows works with Borland compilers).

If I can make a guess, learn to program first, then learn OpenGL. It's crucial to do it this way.

mikau
03-20-2006, 03:05 PM
I know a bit about C++, about classes, loops, pointers, references, if statements. I was able to do a lot with game maker and I used almost none of the point and click functions, did everything from code.

I would learn programming first but self studying from books has prooved difficult. I need something to practice with to retain the knowledge and comit it to memory, otherwise I forget stuff too fast.

How do I include the windows library to my linker?

mikau
03-20-2006, 08:09 PM
plz! Need help! :-(

k_szczech
03-20-2006, 09:26 PM
Hi!
First - launch your IDE and create new project - don't just open a .cpp file - your IDE should automatically create 'WinMain' or 'main' function and add all libraries you need to compile your program. And about that 'main' - windows applications start with 'WinMain' and windows console applications start with 'main'. Your compiler probably tried to create console app. and didn't found 'main' function in your code.

Then you must add additional libraries you want to use.
To run your program you must compile it and then link it. Your IDE will do both at once, but you should know what you need to compile and what to link the program.

To compile opengl program you need to add:
#include <gl/gl.h> in every file that uses opengl

To link opengl program you must add opengl32.lib library to your project. These libs are files, where all these 'unresolved externals' can be found.
To add library to your project look for project settings in your IDE's menus - when you open project settings go to linker section. You should find list of additional libraries there - add what you need.

what libs you need:
gl.h -> opengl32.lib
glaux.h -> glaux.lib
glu.h -> glu32.lib
I don't use glu nor glaux, so I can't tell for sure if I gave you correct library names for these - simply search your IDE's folder if I misspelled something.

This should be enough for a start. If you get through this get your hands on some tutorials.

mikau
03-21-2006, 12:55 PM
Thank you very much! You answered a lot of questions!