Solved

1) error LNK2001: unresolved external symbol _main 2) Debug/first.exe : fatal error LNK1120: 1 unresolved externals

Posted on 2004-08-31
7
410 Views
Last Modified: 2008-02-01
Hi all, I am very new to VC++ ... I have a book in first chapter, I tried to compiled it and it went well. However, when I tried to build first.exe ... I got two errors .... I do not know how to solve it. I have save this program/project in my own directory("C:\MyFolder\C++\WindowsProg\First\"), not sure if that's effects building the .EXE ... Below are my program code and errors ... Kindly take a look and hope to hear from experts. Thank you very much for your time.

--------------------Program Code------------------------------------------
// first.cpp : Defines a window's appearing for the application.
//

#include "stdafx.h"
#include <windows.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{

      WNDCLASS WndClass;
      WndClass.style = 0;
      WndClass.cbClsExtra = 0;
      WndClass.cbWndExtra = 0;
      WndClass.lpfnWndProc = WndProc;
      WndClass.hInstance = hInstance;
      WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
      WndClass.hCursor = 0;
      WndClass.hIcon = 0;
      WndClass.lpszMenuName = 0;
      WndClass.lpszClassName = "WinProg";

      RegisterClass(&WndClass);

      HWND hWindow;

      hWindow = CreateWindow("WinProg", "Window", WS_OVERLAPPEDWINDOW, 0,0, 400, 400, NULL, NULL, hInstance, NULL);


      ShowWindow (hWindow, nCmdShow);

      UpdateWindow (hWindow);

      MSG Message;

      while(GetMessage(&Message, NULL,0,0))
      {
            
            DispatchMessage(&Message);

      }

      return (Message.wParam);

}

// Function: LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
      
      switch(uiMessage)
      {
            
            case WM_DESTROY:
                  PostQuitMessage(0);
                  return 0;

            default:
                  return DefWindowProc (hWnd, uiMessage, wParam, lParam);

      }


}

-------------------------------------------------------------------------------




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

first.exe - 2 error(s), 0 warning(s)

-------------------------------------------------------------------------------
0
Comment
Question by:hbcontract
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11943851
Go to your project settings, choose the 'Link' tab and locate '/subsystem:console' in the text field at the bottom of that page. Change that to read '/subsystem:windows'. The error message indicates that your project settings are for a console app, whereas you are trying to create a GUI application.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11943878
You created a Win32 Console Application. That is supposed to have a main() function rather than a WinMain() function.

You need a Win32 Application (no console) for the prog above. Goto the 'Link' tab of your 'Project Settings' and edit the 'Project Options' field. Replace  /subsystem:console by /subsystem:windows and rebuild all.

Regards, Alex


 
0
 

Author Comment

by:hbcontract
ID: 11944151
How did you guys know I am using Win32 console application? I am trying to find what kind of application I was selecting, but not success ... how I can know what kind of application I was selecting? Coz' from what I know, I did selected Win32 Application ... not console ... unless I mis-select Win32 console application ... Thanks.
0
 
LVL 86

Accepted Solution

by:
jkr earned 40 total points
ID: 11944171
>> How did you guys know I am using Win32 console application?

Because of the error message :o)

'main()'  is needed for a console app, whereas 'WinMain()' is for GUI applications.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
thread-safe code in c++ 2 122
c++, dynamic object by json 1 60
Error creating a new C++ project in ,net 20 51
How to convert Structure to vector of byte and vice versa 5 31
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question