Sign in to follow this  
Spippo

unresolved external '_main' referenced error

Recommended Posts

Hi, I'm new to window-programming, and I bought myself a book about games-programming. It uses borland c++ to write games in Win32 API. I use borland c++ builder 3, and when i try to run the files, i get this error:
Quote:
unresolved external '_main' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER3\LIB\COX32.OBJ.
does anybody know what to do with this?

Share this post


Link to post
Share on other sites
If your doing a Win32 (non-console) app, you'll need to use WinMain - not main - so that may be your problem. Could we see the code? That would help a lot.

[edit: Reading your post a second time, it sounds like your trying to run some code from a Win32 book. If that's the case, (I haven't used Borland C++) but make sure you compile it as a Win32 application - not a Win32 console application.]

Share this post


Link to post
Share on other sites
OK, I made a application now, and now it gives me errors about the icons I added in the .rc file. It sais:

Quote:

Declaration terminated incorrectly.


Here are my codes:

Unit1.h

//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif




Unit1.cpp

//-----------------------------------------------------------------
// Skeleton Application
// C++ Source - Skeleton.cpp
//-----------------------------------------------------------------

//-----------------------------------------------------------------
// Include Files
//-----------------------------------------------------------------
#include "Unit1.h"
#include "Skeleton.rc"

//-----------------------------------------------------------------
// 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);
}




Resource.h

//-----------------------------------------------------------------
// Skeleton Resource Identifiers
// C++ Header - Resource.h
//-----------------------------------------------------------------

//-----------------------------------------------------------------
// Icons Range : 1000 - 1999
//-----------------------------------------------------------------
#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001




Skeleton.rc

//-----------------------------------------------------------------
// Skeleton Resources
// RC Source - Skeleton.rc
//-----------------------------------------------------------------

//-----------------------------------------------------------------
// Include Files
//-----------------------------------------------------------------
#include "Resource.h"

//-----------------------------------------------------------------
// Icons
//-----------------------------------------------------------------
IDI_SKELETON ICON "Skeleton.ico"
IDI_SKELETON_SM ICON "Skeleton_sm.ico"


Share this post


Link to post
Share on other sites
It appears that your project is configured as a command line program. The start up code contained in the cox32.obj file is trying to call your main() function, but you don't have one. Your code is for a Windows program, since you have a WinMain() function.
Check yor project settings and make sure that C++ Builder knows you are trying to build a Windows executable, not a command line executable.

Shawn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this