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

Home Posts Topics Members FAQ

Linker error

Hi, I am new to using Visual C++ and trying to test it out. This is the
simple program I wrote to test it:

#define WIN32_LEAN_AND_ MEAN

#include <windows.h> // the main windows headers
#include <windowsx.h> // a lot of cool macros

// main entry point for all windows programs
int WINAPI WinMain(HINSTAN CE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
// call message box api with NULL for parent window handle
MessageBox(NULL , "THERE CAN BE ONLY ONE!!!",
"MY FIRST WINDOWS PROGRAM",
MB_OK | MB_ICONEXCLAMAT ION);

// exit program
return(0);

} // end WinMain

ok, it will compile no problem but when it comes to linking I get the
following error:

Linking...
LIBCD.lib(crt0. obj) : error LNK2001: unresolved external symbol _main
Debug/demo2_2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

I get this error when using either Visual C++ 5.0 or 6.0

the file LIBCD.lib is resident in the lib folder...

Any help much appreciated, Thanks
Jul 23 '05 #1
4 1604

----- Original Message -----
From: "Red Hammer" <ch************ ********@inspir e.net.nz>
Newsgroups: alt.comp.lang.c ++.help,alt.com p.lang.learn.c-c++,comp.lang.c ++
Sent: Monday, July 04, 2005 8:20 PM
Subject: Linker error

Hi, I am new to using Visual C++ and trying to test it out. This is the
simple program I wrote to test it:

#define WIN32_LEAN_AND_ MEAN

#include <windows.h> // the main windows headers
#include <windowsx.h> // a lot of cool macros

// main entry point for all windows programs
int WINAPI WinMain(HINSTAN CE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
// call message box api with NULL for parent window handle
MessageBox(NULL , "THERE CAN BE ONLY ONE!!!",
"MY FIRST WINDOWS PROGRAM",
MB_OK | MB_ICONEXCLAMAT ION);

// exit program
return(0);

} // end WinMain

ok, it will compile no problem but when it comes to linking I get the
following error:

Linking...
LIBCD.lib(crt0. obj) : error LNK2001: unresolved external symbol _main
Debug/demo2_2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

I get this error when using either Visual C++ 5.0 or 6.0

the file LIBCD.lib is resident in the lib folder...

Any help much appreciated, Thanks


You are mixing window's code with non windows code. All programs must have
a: int main(whatever) function as the initial function to call.

You won't see that call a lot of times in windows programs because it's
hidden down in windows initialization, which would eventually call WinMain.
Since you aren't using those, just change

int WINAPI WinMain(HINSTAN CE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)

to

int main()

as for all the parameters that aren't being passed, you aren't using them
anyway.

You need to study windows programming if you want to do windows. Otherwise
you'll be writing console programs.
Jul 23 '05 #2
Red Hammer wrote:
Hi, I am new to using Visual C++ and trying to test it out. This is
the simple program I wrote to test it:

#define WIN32_LEAN_AND_ MEAN

#include <windows.h> // the main windows headers
#include <windowsx.h> // a lot of cool macros


[snip]

This does not pertain to the standard C++ language. Please ask in a Windows
or Visual C++ newsgroup. A number of suitable groups are listed here:
http://www.slack.net/~shiva/welcome.txt

DW
Jul 23 '05 #3

Any help much appreciated, Thanks


What are the compiler options did you choose? Make sure you defined the
macro WIN32, either by #define (before #includes), or by the /DWIN32
compiler option.

ben
Jul 23 '05 #4
Me
> int WINAPI WinMain(HINSTAN CE hinstance,

LIBCD.lib(crt0. obj) : error LNK2001: unresolved external symbol _main


You're probably setting the linker flag /subsystem:conso le so either
remove it or set it to /subsystem:windo ws.

Jul 23 '05 #5

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
9506
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
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
6755
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.