Re: linker error
On 2007-07-23 17:40, kath.neumann@web.de wrote:
Hi,
I just started to get a grip on C++ and and went through the tutorial.
However, not even the standard "hello world" exercise works out :( I
do get a linker error "[Linker Error] Unresolved external 'WinMain'
referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\C0W32.OBJ"
my code (Borland C++ builder 5) is as follows:
#include <condefs.h>
Non-standard header, and not used, skip it.
#include <iostream.h>
Old header, nowadays all standard headers are included without the .h
suffix, so it should be just #include <iostream>
#include <conio.h>
Non-standard, it's generally a good idea to stay away from such headers
while learning C++, since it reduces the changes of learning any bad habits.
#pragma hdrstop
Non-standard and I don't know what it does. Keep it if you think it's
useful, but considering the name of the pragma it's probably something
that should be used in header-files.
//---------------------------------------------------------------------------
int main (int argc, char **argv)
Unless you actually parse the command line arguments I would recommend
to use the simpler form: int main().
{
cout << "Hello World!" << endl;
This should give you a compiler error, cout is not defined. Either
include the namespace (std::cout << ...) or put 'using namespace std;'
above the main-function. I prefer the first but that's just me.
cout << endl << "press any key to continue...";
Ditto.
getch();
If used just to prevent the console from closing as soon as the program
is done, I think it's better to use std::cin.get() which will require
you to press enter. If you use this you can get rid of the include for
conio.h also.
return 0;
}
Any idea?
You have probably specified it as a windows GUI program when you created
the project (or whatever Borland calls it), you need to specify it as a
native win32 project.
By the way, it seems to me that Borland C++ Builder 5 is quite old by
now, at least one newer version is out and you might want to consider
upgrading. If cost is an issue there are free alternatives, both Visual
C++ 2005 from MS and DevC++ (which comes with gcc).
--
Erik Wikstr?m