473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

linker error

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>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------
int main (int argc, char **argv)
{
cout << "Hello World!" << endl;
cout << endl << "press any key to continue...";
getch();
return 0;
}
Any idea?

THANKS!

kath

Jul 23 '07 #1
12 7662
ka**********@web.de wrote:
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>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------
int main (int argc, char **argv)
{
cout << "Hello World!" << endl;
cout << endl << "press any key to continue...";
getch();
return 0;
}
Any idea?
Unfortunately, yes. You're building this as a Windows application.
If so, then your application doesn't start in 'main', it has to start
in 'WinMain', which you don't have and that's what the linker is
complaining about. MS Windows programming is not the same as just
plain programming. That's why you probably want to set aside the
"Windows" side of things for now and switch to creating what is known
as "Console Applications". See appropriate settings described in the
help system for your compiler. Or ask in the newsgroup dedicated to
your compiler (see the 'borland.public.*' hierarchy).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 23 '07 #2
On 2007-07-23 17:40, ka**********@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
Jul 23 '07 #3
On 23 Jul., 17:55, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
kath.neum...@web.de wrote:
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>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop
//---------------------------------------------------------------------------
int main (int argc, char **argv)
{
cout << "Hello World!" << endl;
cout << endl << "press any key to continue...";
getch();
return 0;
}
Any idea?

Unfortunately, yes. You're building this as a Windows application.
If so, then your application doesn't start in 'main', it has to start
in 'WinMain', which you don't have and that's what the linker is
complaining about. MS Windows programming is not the same as just
plain programming. That's why you probably want to set aside the
"Windows" side of things for now and switch to creating what is known
as "Console Applications". See appropriate settings described in the
help system for your compiler. Or ask in the newsgroup dedicated to
your compiler (see the 'borland.public.*' hierarchy).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Hi Victor,
it is running now, thanks for your help!!! I created it as console
application, that was indeed the reason. thanks for this tip :-)
Cheers,
Kathleen

Jul 23 '07 #4

<ka**********@web.dewrote in message...
On 23 Jul., 17:56, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
>Use some standard-compliant compiler. Typical options are g++(linux),
devc++(windows), but I am sure there are other options too.
>Hi,
thanks, it is running now :)
thanks for your recommendations on compiler, I'll check that soon!
Cheers, Kathleen
FYI: Dev-C++ is not a compiler, it is an IDE. There is an option to download
a Dev-C++ package that contains the GNU GCC(MinGW) compiler.

Dev-C++ IDE: http://www.bloodshed.net/

--
Bob R
POVrookie
- -
MinGW (GNU compiler): http://www.mingw.org/
MinGWStudio http://www.parinyasoft.com/ (GNU/Linux & window$)
wxWidgets URL: http://www.wxwidgets.org
Code::Blocks http://www.codeblocks.org/
Jul 23 '07 #5

Erik Wikström <Er***********@telia.comwrote in message...
>
.... or put 'using namespace std;'
above the main-function.
Why not *in* main()?

--
Bob R
POVrookie
Jul 23 '07 #6
On Jul 23, 7:02 pm, "Alf P. Steinbach" <al...@start.nowrote:
* Victor Bazarov:
[...]
g++ supports standard "main" by default,
Visual C++ supports standard "main" when using appropriate switches (by
default Visual C++ is also non-standard-conforming wrt. exceptions, RTTI
and for-loop syntax, so it must be browbeaten into submission).
Aren't they all? You need -std=c++98 -pedantic with g++, and
God knows how many options with Sun CC. Add to that the fact
that pure C++ compliance locks you out of a lot of Posix, and
what's a programmer to do?
which you don't have and that's what the linker is
complaining about. MS Windows programming is not the same
as just plain programming. That's why you probably want to
set aside the "Windows" side of things for now and switch to
creating what is known as "Console Applications".
Good advice.
I know this is off topic, but the issue comes up so often: what
the hell is a "console application"? How does it differ from
any other application, other than, perhaps, it doesn't use
certain libraries? (In which case, of course, you don't need to
click anything. Just don't include the appropriate headers, nor
link against the corresponding library.)

Unless I've misunderstood something greatly, in the end, an
application is an application. If it invokes some system
function which opens a window, and plays around in it, then it
is a GUI (or Windowing) application, but that's a result of the
code the programmer wrote, and nothing else. The applications I
write don't normally do this: are they automatically console
applications (even if they are started by a cronjob, or at
system start-up, with cin, cout and cerr connected to
"/dev/null")?
I'd add: use command line tools for building.
Is there any other way? All the IDE's that I know (admittedly,
NOT Visual Studio) do is generate command lines.
An IDE adds too much "helpful" stuff that just gets in the way.
:-) Boy can I agree with you there.

At least for production code. I can imagine that when learning,
"one thing at a time" is not a bad policy, and if you could find
an IDE which actually worked correctly and usefully, it would be
nice. But professionally, never.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 24 '07 #7
On Jul 23, 5:56 pm, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 23, 8:40 pm, kath.neum...@web.de wrote:
Use some standard-compliant compiler. Typical options are g++(linux),
devc++(windows), but I am sure there are other options too.
Watch it. I have no idea what devc++ is, but g++ is not
standards compliant, by a long shot. "g++ -std=c++98 -pedantic"
tries to be, up to a certain point, but even it ignores some
major features of C++ (like export).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 24 '07 #8
James Kanze wrote:
[..] If I look at my
Windows system, I don't see any difference between applications;
they're all .exe files, regardless of what they do. As far as I
can tell, all of the facilities of the OS are there for all
programs to use, if they want.
If I look at my Windows desktop, they all look like tiny pictures.
As far as I can tell, there are no .exe files.
[..off topic snipped..]
MSDN is your friend (if you really want to know about Windows,
that is). It looks like you were at least curious. Well, don't
you know that there are newsgroups for those discussions? And
here is a link (courtesy of MSDN) answering at least one question
(how to distinguish between a console app and non-console app):
http://support.microsoft.com/kb/90493

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 25 '07 #9
On Jul 25, 2:36 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
James Kanze wrote:
[..] If I look at my
Windows system, I don't see any difference between applications;
they're all .exe files, regardless of what they do. As far as I
can tell, all of the facilities of the OS are there for all
programs to use, if they want.
If I look at my Windows desktop, they all look like tiny pictures.
As far as I can tell, there are no .exe files.
Come now. How did those icons get there? Even I know that you
can open a properties dialog, and specify the command for the
program, and I rarely use Windows.
[..off topic snipped..]
MSDN is your friend (if you really want to know about Windows,
that is). It looks like you were at least curious.
All I really wanted was a definition of a term that I'd seen
often enough here, and for which I couldn't figure out any
reasonable meaning. Alf's article filled the bill (and then
some, since I now not only know what was meant, but what I'll
have to do if I ever have to develop applications under
Windows.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 25 '07 #10

James Kanze <ja*********@gmail.comwrote in message...
...., and I rarely use Windows.
Ah, so you are the guy that dropped B. Gates to number 2 in the 'worlds
richest' list!! <G>
Good job, friend!

--
Bob R
POVrookie
Jul 26 '07 #11
In article <11**********************@k79g2000hse.googlegroups .com>,
ja*********@gmail.com says...
On Jul 25, 6:47 pm, Jerry Coffin <jcof...@taeus.comwrote:
[ ... ]
What's a PE file? And what do you mean by "optional header"?
I'm sure that .exe file have a specific format, just as a.out
files do under Unix; do you mean a header section in this
format?
Sorry -- PE is "Portable Executable" format, which is a variation on
COFF, and yes, it's the current format for Windows executables. COFF
defines a couple of fields for what it calls an optional header -- but
to be a PE file, that optional header has to be included in a specific
format.

[ ... ]
That means portable code that uses 'main' will become a console
subsystem program unless you specify otherwise.

But I can specify otherwise. Why not?
I'm not sure I follow. Why not what? If you mean, why wouldn't you do
that, the main reason would be that you plan to use the console streams,
so you want them set up by default, which will happen if it's marked for
the console subsystem, but not if it's marked for the windows subsystem
(at least the startup code supplied by the compilers I've looked at
didn't do include that by default...)

[ ... ]
That's what I'd always thought. (On the other hand, there are
significant differences between the way Windows handles .dll's,
and Unix handles .so's. My impression, in fact, is that they
are much like the differences between how the systems handle the
way you start a program. Under Windows, the decisions are
handled upstream, by the person who provides the program/DLL;
under Unix, they're made by the user, when he uses it.)
I'm not sure I understand exactly what differences you're talking about
here...

[ ... ]
As far as sophistication goes, I suspect it's a much a matter of
viewpoint as anything else -- when I run Unix (or Linux, BSD, etc.) I
get the feeling of having just stepped back 10 or 15 years as well...

With regards to what? I don't have the applications that I have
under Windows, or they don't look as sleek, but at the system
level, I've got a lot more functionality: multiple desktops,
windows on many different machines, etc.
Well, to continue one of your examples, Windows does support multiple
desktops -- but I haven't been able to find X/Unix functionality similar
to the multiple window stations supported by Windows. Under Windows,
each desktop lives in a window station. Most "global" objects like the
clipboard are only really shared among the desktops in a window station.
Under X, the clipboard is managed by a process of its own, but I haven't
seen a capability to designate (for example) that these three desktops
share one clipboard, while those two share a different one.

[ ... ]
This _is_ somewhat different: Windows only provides on way to start a
program, but it does NOT map to much of anything. The real entry point
for a program always has the signature 'unsigned int entryPoint(void)'.
It's (always) up to some code in the program itself to do things like
retrieving and parsing its command line, if it chooses to do so at all.

All of which is transparent to the C++ programmer, of course:-).
Yes -- unless he chooses to get involved, of course.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 26 '07 #12
On Jul 26, 10:55 pm, Jerry Coffin <jcof...@taeus.comwrote:
In article <1185464835.026416.133...@k79g2000hse.googlegroups .com>,
james.ka...@gmail.com says...
On Jul 25, 6:47 pm, Jerry Coffin <jcof...@taeus.comwrote:
[ ... ]
That means portable code that uses 'main' will become a console
subsystem program unless you specify otherwise.
But I can specify otherwise. Why not?
I'm not sure I follow. Why not what?
Just "why not?" Why not do it like Microsoft does? It's no
worse (nor any better) than some other solutions.
[ ... ]
That's what I'd always thought. (On the other hand, there are
significant differences between the way Windows handles .dll's,
and Unix handles .so's. My impression, in fact, is that they
are much like the differences between how the systems handle the
way you start a program. Under Windows, the decisions are
handled upstream, by the person who provides the program/DLL;
under Unix, they're made by the user, when he uses it.)
I'm not sure I understand exactly what differences you're talking about
here...
The fact that with Windows DLL's, you specify which symbols are
exported in the source file, using language extension (or in a
second file, which will be read by the linker), where as with
Unix, you specify whether other so's can see the symbols in your
so by means of an option to dlopen, when you load the object.
Under Windows, the author of the dynamically linked object
chooses what will and what will not be visible; under Unix, the
user chooses when loading the object. (But that's a radical
simplification, of course.)
[ ... ]
As far as sophistication goes, I suspect it's a much a matter of
viewpoint as anything else -- when I run Unix (or Linux, BSD, etc.) I
get the feeling of having just stepped back 10 or 15 years as well...
With regards to what? I don't have the applications that I have
under Windows, or they don't look as sleek, but at the system
level, I've got a lot more functionality: multiple desktops,
windows on many different machines, etc.
Well, to continue one of your examples, Windows does support multiple
desktops -- but I haven't been able to find X/Unix functionality similar
to the multiple window stations supported by Windows. Under Windows,
each desktop lives in a window station. Most "global" objects like the
clipboard are only really shared among the desktops in a window station.
Under X, the clipboard is managed by a process of its own, but I haven't
seen a capability to designate (for example) that these three desktops
share one clipboard, while those two share a different one.
I'm not sure what the difference is under Windows, but it sounds
like you've basically got two different terminals under X. (A
terminal under X can have more than one screen.)
[ ... ]
This _is_ somewhat different: Windows only provides on way to start a
program, but it does NOT map to much of anything. The real entry point
for a program always has the signature 'unsigned int entryPoint(void)'.
It's (always) up to some code in the program itself to do things like
retrieving and parsing its command line, if it chooses to do so at all.
All of which is transparent to the C++ programmer, of course:-).
Yes -- unless he chooses to get involved, of course.
Agreed. (IMHO: Not having access to the actual command line
is a flaw in the Unix design. There are cases where you want to
differ e.g. filename expansion; under MS-DOS, I had a library
which broke up the command line something like the way Unix
does, including expansion of things like *.c. And one of my
"standard" options was -R, which means recurse on the current
directory, expanding the filenames in all of its subdirectories
as well. And a -o option which would accept such names as well,
mapping each input filename to a corresponding output filename.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 27 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Baloff | last post by:
Hello I have this linker error which makes me think that the definition file is not being seen by the linker, this code is taken from "Thinking in C++, 2nd Edition, Volume 1, Annotated Solutions...
1
by: Laszlo | last post by:
Hi all, As a novice I installed PostgreSQL 7.2.1 on Win32 and works, Borland C++Builder Enterprise Suite 5.0 (build 12.34) what works too. I decided to combine these two programs and develop a...
5
by: Pradnyesh Rane | last post by:
Hi, I am encountering the following linker error on VC7. LINK : fatal error LNK1171: unable to load ole32.dll This error is only encountered for the "Debug" configuration. The project...
3
by: Steve Baer | last post by:
I recently read your whitepaper under the "extremely long link times" post and have a question that I was hoping you could answer. My question is based on the following paragraph: Directives...
9
by: Peter Oliphant | last post by:
For some reson my code is generating a LNK1215 error, which 'suggests' I re-install VS C++. So I did. which did NOT solve the problem. The weid part is it seems to be caused by my one CPP file, but...
3
by: Chucker | last post by:
Hi Folks, I got a Wrapper Dll around a native C++ static library. In .NET 1.1 this worked fine. When moving to .NET 2.0 I get a couple of unresolved externals / linker errors: Error 16 error...
1
by: Felix | last post by:
After porting a project from VC6 to VC.NET 2003 I have a very strange problem generating link error 1104 for import libraries. I just ported the project and made some small adaptions so it fits...
4
by: yOtA | last post by:
I get this Linker Errors while compiling my program: Error: Unresolved external 'vminit()' referenced from C:\TESTE\TESTE.OBJ Error: Unresolved external 'vmalloc(void *, int, unsigned int,...
1
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- ...
3
by: Rahul | last post by:
Hi Everyone, I have the following polymorphic classes, class Shape { public : virtual void draw() { } virtual void sample();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.