473,789 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\C BUILDER5\LIB\C0 W32.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 7726
ka**********@we b.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\C BUILDER5\LIB\C0 W32.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**********@we b.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\C BUILDER5\LIB\C0 W32.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...@com Acast.netwrote:
kath.neum...@we b.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\C BUILDER5\LIB\C0 W32.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**********@w eb.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.no wrote:
* 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 objektorientier ter Datenverarbeitu ng
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...@we b.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 objektorientier ter Datenverarbeitu ng
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...@com Acast.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 objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 25 '07 #10

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

Similar topics

12
801
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 Guide" Using Dev-C++ 4.9.9.2, The error is: undefined reference to ‘f(int)’ all the following files are in the same dir. thanks
1
5010
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 simple GUI app to display datas queried from PostgreSQL. I did make the following changes in the project's settings: Project->Properties->Directories->Include path += C:\Program
5
6053
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 successfully compiles/links in "Release" configuration. Any help is welcome.
3
1779
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 The linker's handling of directives left something to be desired in VC2003, and for this reason code with lots of directives can suffer. In particular __declspec(export), as it's likely the most common linker directive. Besides that, don't export...
9
2014
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 not sure how. It compiled just fine. Then I made a simple change and re-compiled, and got the 1215 error. After that I have to bring back in an old version of the code to make it work again (not fun)... This seems like a REAL LINKER error, not...
3
8089
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 LNK2028: unresolved token (0A000007) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: virtual __thiscall...
1
2270
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 the new IDE. The project itself links against some import libraries belonging to dll's I wrote (these dll's have been ported too, of course). To keep things simple I only use one import library here. To tell the linker it should link against
4
29321
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, unsigned int)' referenced from C:\TESTE\TESTE.OBJ Error: Unresolved external 'vmcomplete(void *)' referenced from C:\TESTE\TESTE.OBJ Error: Unresolved external 'LogError(char *, int, char *, int)' referenced from C:\TESTE\TESTE.OBJ
1
4164
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 ----------------------- Error: Unresolved external 'ImqMgr::~ImqMgr()' referenced from C:\DOCUMENTS AND SETTINGS\228753\MY DOCUMENTS\BORLAND STUDIO PROJECTS\DLLEXERCISE\DEBUG_BUILD\MANI.OBJ Error: Unresolved external 'ImqObj::~ImqObj()' referenced from C:\DOCUMENTS AND...
3
3600
by: Rahul | last post by:
Hi Everyone, I have the following polymorphic classes, class Shape { public : virtual void draw() { } virtual void sample();
0
9661
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10403
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9978
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9015
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4087
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2904
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.