Solved

glut/VC++4.0 difficulty

Posted on 1998-08-15
15
567 Views
Last Modified: 2012-08-14
whenever I try to use glut with openGL in my VC++4.0 compiler, the program compiles but on the linking stage I get the error

libcd.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16

can anybody tell me whats going on?
0
Comment
Question by:Booth882
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 1

Author Comment

by:Booth882
ID: 1170401
Edited text of question
0
 
LVL 1

Author Comment

by:Booth882
ID: 1170402
as in how I can go about resolving the unresolved external symbol _WinMain@16
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1170403
WinMain() is the entry point to a GUI win32 application.  Like main() is for a regular c++ application.  Did you declare a WinMain() procedure?  You must declare a WinMain(), not main() procedure..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 1170404
WinMain() must be declared like

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
);

You can search for "WinMain" in the on-line docs to learn more about the parameters.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1170405
good, but what do I put as hInstance and lpCmdLine?  I have no clue
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170406
What do mean?  You don't call WinMain() so you don't have to supply those parameters.  Your WinMain() procedure will be called by the OS with these parameters "filled in".  Just like the "regular" main() procedure used to be called with the argc and argv parameters "filled in".

You are trying to create a windows GUI program aren't you?  If so you will have a WinMain() instead of a main().  It will take the parameters I listed above.  Look at the docs on winmain by searching for "WinMain" in the on-line help.

If you aren't trying to make a windows GUI program, you should have just a main() not a winmain().  But in that case you need a different project type.  You need a project to create a win32 console application.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1170407
ok heres the deal.  I have a program with a main loop, like

void main()
{
    code....
}

but when I link it I get the error above.  So as I understand you I need a WinMain() instead of a main(), which would make it

int WINAPI WinMain(hInstance, prevInstance, lpCmdLine, nCmdShow)
{
    code....
}

if that is the case, what do I put in as arguments?  I mean, what do I pass in as hInstance and prevInstance and lpCmdLine and nCmdShow?  

if that is not the case, please help me to understand what exactly it is that I need to do to get my program to link!
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170408
first of all:

In a typical C++ program you have

int main(int argc, char * argc)
{
 code
};

Note that main returns an int, it is not void.  You can ussualy get away declaring main() as returning void, but someday you won't....

Note that main() takes two arguments.  However, you are allowed to declare main without them, like

int main()
{
  code
};

Now that is for a standard C++ program.  Microsoft and then Borland and others decided to break the rules a little.  For a windows program you don't need (actually you can't have) a main() procedure.  Instead you have a procedure called WinMain() that serves the same purpose.  But WinMain() has two differences.  First, it is named differently--that is important because this name is required and main() is not allowed.  Second, it takes a different set of parameters (Ones that you may not alter.).

Now you ask?
>> what do I pass in as hInstance and prevInstance and lpCmdLine and nCmdShow?

Well, what do you pass when you call main()?  Huh???  You don't call main().  Main is called when the program starts.  You never call it.  Same thing with WinMain().  WinMain() is called when the program starts, you don't call it.  You just put code inside WinMain() that you would have placed inside main().  Again WinMain() replaces main().
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170409
Note that all this is true only if you are trying to create a GUI program (a "real" windows program).  If you want to create a win32 console program, then you would have an ordinary main().   A win32 console program looks like an "old fashioned" program.  That is, it displays just text, it doesn't have menus and buttons etc.

 I can't tell which you want.  But given the error you are getting, VC is trying to make a GUI program, thus, you need a WinMain().  If you want a consoel program, you cn keep your main(), but need to switch to a console project, not a GUI project.  

Thus if you still can't get it to compile, I need to know which type of program you are creating.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1170410
so show me how I would write it then.  is it just

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR lpcmdline, int ncmdshow)
{
    code....
}

then?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170411
Exactly.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1170412
but to use glut I must call

   glutInit(int * argc, char ** argv)

which with main like

  int main(int argc, char ** argv)

I can simply go

   glutInit(& argc, argv);

my question is:  What are the WinMain equivalents to argc and argv?  are there even equivalents?  can I call such a function as glutInit using a WinMain program?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170413
WinMain() gets a single parameter string, unlike main()'s nicely parsed parameter array.  Thus if you call a windows program called PROG with 3 parameters, you will get a string like
"PROG PARAM1 PARAM2 PARAM3"

You could convert this string into the data that glutinit needs. You would parse this information into an argv-like array and calculate an argc value.  (using strtok() it would be pretty easy)

However, it might not be worth it.  Since it is rare for a windows program to be called with parameters, you probably could just pass a 0 argc to glutinit indicating there are no prameters.  (I assume glutinit doesn't have to have parameters)  

I should mentuon that I am not familar with glut.  But considering the way it takes parameters, it suggests that it was not intended to be called from a true windows program.  Do you know if if can be?  What does it do?
0
 
LVL 1

Author Comment

by:Booth882
ID: 1170414
perfect!  its all working.  thanks for your help once again
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170415
Just out of curiousity--What did you do?  pass a 0 argc or did you create an argvc-like array.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question