Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to compile windows program in borland 5.5

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
My Borland 5.5 c++ compiler won't compile even a simple windows program. When I try the same program in VC++ it compiles ok.

The error I get in Borland is:

Error: Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ

what does this mean?
 
If your program goes something like this:

int main()
{
//code here
return 0;
}

Then you need to compile your program as a 32bit windows console application.... Otherwise if it starts something like this:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE PrevInstance, LPSTR lpCmdLine, INT nCmdShow)

You just compile it as a normal 32bit windows application.



Kim_Christensen@telus.net
 
Actually the program is already a win32 application with the the proper windows functions. All it does is display a window and compiles and runs fine in VC++. The problem seems to be something else. Here's the code:



#include <windows.h>

static char pClassName[] = &quot;TheClass&quot;;
static HINSTANCE ghInst = 0;

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case CM_CLOSEWIN: DestroyWindow(hwnd); break;
case WM_CLOSE: DestroyWindow(hwnd); break;
case WM_DESTROY: PostQuitMessage(0); break;
default: return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wce;
HWND hwnd;
MSG msg;
ghInst = hInstance;

wce.cbSize = sizeof(WNDCLASSEX);
wce.style = 0;
wce.lpfnWndProc = WndProc;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = ghInst;
wce.hIcon = LoadIcon(0, IDI_WINLOGO);
wce.hCursor = LoadCursor(0, IDC_ARROW);
wce.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wce.lpszMenuName = 0;
wce.lpszClassName = pClassName;
wce.hIconSm = LoadIcon(0, IDI_WINLOGO);

if(!RegisterClassEx(&amp;wce))return 0;

hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, pClassName, &quot;title&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
800, 600, 0, 0, ghInst, 0);

if(hwnd == 0) return 0;

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&amp;msg, 0, 0, 0))
{
TranslateMessage(&amp;msg);
DispatchMessage(&amp;msg);
}
return 0;
}
 
Hi,
I use batch files. Below is a sample.

FIRST FILE TO COMPILE SOURCE C OR CPP

bcc32 -c -w- -tW wingen.cpp


SECOND TO COMPILE RC FILE

brcc32 -w32 myrsrce.rc

THIRD TO LINK OBJ AND RES *NOTE &quot;ilink32&quot; IS NOT A LINK BUT THE LINKER PROG

ilink32 -Tpe -aa c0w32.obj wingen.obj , wingen.exe, ,import32.lib cw32mt.lib, ,myrsrce.res

del *.ils
del *.ilf
del *.ilc
del *.ild
del *.tds
del *.map

DEL LINES TO GET RID OF INTERMEDIATE FILES

I put the deviders in CAPS to seperate the three files.
wingen.cpp is what I wrote to use as a template(NOT CPP template)for starting a windows program.

Hope this helps.

Pappy
You learn somrthing everyday.
 
Thank you Pappy1942. From your batch script I see the problem now. It was the -tW option.

bcc32 test.cpp
doesn't work for windows apps....

bcc32 -tW test.cpp
does.

so for example:

#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int cmdShow)
{MessageBox(0, &quot;ok&quot;, &quot;ok&quot;, MB_OK); return 0;}

compiles and runs ok displaying a simple pop-up.
Thanks a bunch.

Thanks also zBuilder for responding.
 
Yeah. I'm going to do that next. The whole reason for opting to use borland is because VC++ seems to do do a lot of stuff &quot;for you&quot;. I feel like I'll understand what's going on better if I use a more manual compiler like borland.
 
I found this thread which answers some issues I was asking about. Thanks for the great info Pappy1942. How would one put this ugly mess of -flags and ,,options into a make file? I certainly don't look forward to typing in that ilink32 thing every time! The info on make is very, very sketchy in the documentation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top