Newbie Linking Error

J

Jeff Schwab

LuCk said:
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?
 
L

LuCk

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.
 
J

Jack Klein

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
 
L

LuCk

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
 
J

John Tsiombikas (Nuclear / the Lab)

LuCk said:
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 --
 
L

LuCk

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`
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top