Click to See Complete Forum and Search --> : unresolved external


Fion
April 14th, 1999, 02:03 AM
Hello, everyone.
This is Fion.
I am trying to develop a program in C in the VC++ workstation. Now I am trying to build and debug my
program. The output of the build is:
LIBCD.lib(crto.obj):unresolved external symbol -main
Fatal error 1 unresolved external
I spend a lot of time on this problem, but I can not find out the answer. If I can not solve this problem,
I can not continue my project. So it is ergent for me to solve it. Can any body can help me on this problem,
I will be very appriciate. Thank you very much!!!

Franky Braem
April 14th, 1999, 02:27 AM
Every program you write needs an entry point. In c/c++ this is the main-function. When you write a console application you specifiy this as follows :

void main(void)
{
...
}

When creating a new workspace then select a console application with an empty project.

When your program is a windowsprogram you can use the wizards which implements a WinMain for you.

Fion
April 14th, 1999, 03:26 AM
Hi, Franky,
Thank you very much.
Actually, it is a window program, and I also has a WinMain Function. Is there any other reason for the exist of the bug? Wait for for reply. Say thank to you again!

Franky Braem
April 14th, 1999, 04:00 AM
the declaration of your WinMain should be :

int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nCmdShow);

Is WIN32 defined ?

Use the MFC-wizard. Then you don't have to take care of the WinMain. MFC will do it for you.

Gomez Addams
April 14th, 1999, 11:54 AM
Also, make sure that _CONSOLE is NOT defined and that _WINDOWS IS defined.
These are in the Project settings menu, C/C++ tab, preprocessor settings.

Fion
April 14th, 1999, 08:14 PM
Hi, Gomez
Thank you a lot. I change the setting under project -preprocessor from _CONSOLE to _WINDOWS
And my WinMain function looks like this:
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
MSG msg ;

if (!hPrevInstance)
if (!InitApplication( hInstance ))
return ( FALSE ) ;

if (NULL == (hTTYWnd = InitInstance( hInstance, nCmdShow )))
return ( FALSE ) ;

while (GetMessage( &msg, NULL, 0, 0 ))
{
if (!TranslateAccelerator( hTTYWnd, ghAccel, &msg ))
{
TranslateMessage( &msg ) ;
DispatchMessage( &msg ) ;
}
}
return ( (int) msg.wParam ) ;

}
After I change my setting of project, it still does not work. Any idea? thank you very much!!!!

Gomez Addams
April 14th, 1999, 10:06 PM
To tell you the truth, I am at a loss. Usually when I get in this position I
look at all of the project options I can find. Check the code generation
options (I think you have single threaded, I usually use multithreaded,
dynamic link) and also make sure there is no entry point specified or if
one is delete it if it is not WinMain. If you decide to bail-out on the bug
hunt then make a good backup copy of all of your source and use the
app-wiz to generate a new app. Then replace all of the new stuff with
what you already have (except for the project files - .dsp, and .dsw )
and add your files to the project. I know this is kind of a pain but the
whole project file scene remains a real mystery to me (and everyone I
know) and I sometimes find that I have to punt and start again. I have
had to do this so often that I now have a basic project file that I can use
as a template to make others. I just saved one from the app-wiz and
deleted nearly everything from it. I kept one source file, a resource
script, and the pre-compiled header stuff.

Good Luck and I'm sorry that I can't be more helpful.

Fion
April 15th, 1999, 12:41 AM
Hi, dear Gomez
Sorry for any troublesome that I bring to you.
Thank you for your help very much. I will try it later.
All the best to you, Bye!