Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Newbie Linking Error

Reply
Thread Tools

Newbie Linking Error

 
 
Jeff Schwab
Guest
Posts: n/a
 
      12-29-2003
LuCk wrote:
> I compile a program and there are no compiling errors....but when i go to
> build the program or execute it, i get the following error:
>
> ----------------------------------------------------------
> Linking...
> LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
> Debug/Skeleton.exe : fatal error LNK1120: 1 unresolved externals
> Error executing link.exe.
> ----------------------------------------------------------
>
> I think it has something to do with including the skeleton.ico and the
> skeleton_sm.ico files(icon files)
> but i really dont know. The icon files are in the same directory as the
> skeleton.cpp file.



What would make you think this error had to do with icon files? The
linker is telling you your main function has not been defined, not some
data file.

I guess you're using Windows. Can you compile from a command line, or
do you have only a GUI available?

 
Reply With Quote
 
 
 
 
LuCk
Guest
Posts: n/a
 
      12-29-2003
I compile a program and there are no compiling errors....but when i go to
build the program or execute it, i get the following error:

----------------------------------------------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Skeleton.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
----------------------------------------------------------

I think it has something to do with including the skeleton.ico and the
skeleton_sm.ico files(icon files)
but i really dont know. The icon files are in the same directory as the
skeleton.cpp file.


 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      12-30-2003
On Mon, 29 Dec 2003 06:54:24 GMT, "LuCk" <> wrote
in comp.lang.c++:

> I compile a program and there are no compiling errors....but when i go to
> build the program or execute it, i get the following error:
>
> ----------------------------------------------------------
> Linking...
> LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
> Debug/Skeleton.exe : fatal error LNK1120: 1 unresolved externals
> Error executing link.exe.
> ----------------------------------------------------------
>
> I think it has something to do with including the skeleton.ico and the
> skeleton_sm.ico files(icon files)
> but i really dont know. The icon files are in the same directory as the
> skeleton.cpp file.


All standard C++ programs begin execution at a function provided by
the program named main() that returns an int. Your linker is
complaining that you did not provide such a function, so it is unable
to make a valid C++ program.

If you are making some platform specific program that does not start
with a function named main() that returns an int, it is not standard
C++ and is off-topic here. You need to ask in a group that supports
your compiler and platform.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
Reply With Quote
 
LuCk
Guest
Posts: n/a
 
      12-30-2003
Thankyou for your help so far.....i thought the error was in the linker
because it says Linking...but i guess not. Also i figured nothing was wrong
cause i copied it straight from Teach Yourself Game Programming in 24 Hours.

Here is the code of the .cpp file (Skeleton.cpp)
----------------------------------------------------------


#include "Skeleton.h"

//-----------------------------------------------------------------
// Global Function Declarations
//-----------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM
lParam);

//-----------------------------------------------------------------
// Global Functions
//-----------------------------------------------------------------

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("Skeleton");
WNDCLASSEX wndclass;
HWND hWindow;
MSG msg;

// Create the window class for the main window
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance,
MAKEINTRESOURCE(IDI_SKELETON));
wndclass.hIconSm = LoadIcon(hInstance,
MAKEINTRESOURCE(IDI_SKELETON_SM));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

// Register the window class
if (!RegisterClassEx(&wndclass))
return 0;

// Create the window
hWindow = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
NULL);

// Show and update the window
ShowWindow(hWindow, iCmdShow);
UpdateWindow(hWindow);

// Enter the main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
// Process the message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM
lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;

switch (msg)
{
case WM_PAINT:
// Draw some text centered in the client area of the main window
hDC = BeginPaint(hWindow, &ps);
GetClientRect(hWindow, &rect);
DrawText(hDC, TEXT("This is a skeleton application!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hWindow, &ps);
return 0;

case WM_DESTROY:
// Exit the application
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}


----------------------------------------------------------

When i added:

int main() {
return 0;
}

before the `int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)` function i got a Command prompt that just
quit at the press of any key.
The point of this project is to get a standard Windows window with `This is
a skeleton application` text in the middle.


Regards,
Carl


 
Reply With Quote
 
John Tsiombikas (Nuclear / the Lab)
Guest
Posts: n/a
 
      12-30-2003
LuCk wrote:

> Thankyou for your help so far.....i thought the error was in the linker
> because it says Linking...but i guess not. Also i figured nothing was wrong


The error is indeed during the linking, the linker tries to find your
main function and cannot find one in any of your object files...

> cause i copied it straight from Teach Yourself Game Programming in 24 Hours.
>
> Here is the code of the .cpp file (Skeleton.cpp)
> ----------------------------------------------------------


[.. snip, some off-topic win32 code...]

> ----------------------------------------------------------
>
> When i added:
>
> int main() {
> return 0;
> }
>
> before the `int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
> PSTR szCmdLine, int iCmdShow)` function i got a Command prompt that just
> quit at the press of any key.


and why did you expect to get anything else from a program that just
returns immediately in its main function?

> The point of this project is to get a standard Windows window with `This is
> a skeleton application` text in the middle.
>
>
> Regards,
> Carl


To cut the story short, what that book tries to teach you has nothing to
do with C++ it teaches you how to use some OS libraries (namely Win32
API) to make a program that interacts with a given operating system
(namely Windows) and as a bonus that OS has a wierd convention to have
programs start from a function that is totally different than the
regular main function. thus for all the above reasons it is totally
off-topic here. You might want to check with a more relevant newsgroup
or RTFM on how to tell your linker that you intend to do a Win32 program
(hint).

-- Nuclear / the Lab --

 
Reply With Quote
 
LuCk
Guest
Posts: n/a
 
      12-30-2003
Im not looking for trouble and im not trying to post in the wrong
areas......i didnt know anything about what my problem was (as you can see
from the title) and the book is teaching me how to game program for windows
and in that particular section it shows how to create the screen in which
the game will be played. That wasnt part of the game or game engine...just
the screen. Thankyou for your hint....im hoping to find use for it .....

Regards,
Carl

`Sorry if posting off topic offended anyone here, i didnt intend it to be
that way`



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C Program Linking - newbie question LSunanda@gmail.com C Programming 6 09-16-2006 04:19 AM
Newbie linking problem MagmaGal C Programming 7 11-01-2004 09:49 AM
problems in vc++:Applying setting user breakpoint, unhandled exception ,linking error,runtime error manish C++ 1 04-02-2004 12:33 PM
Undefined Reference Error while linking with g++, STL on LINUX RU C++ 2 08-06-2003 03:28 PM
Newbie linking (ld) question (I think) Rob C Programming 1 07-22-2003 03:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57