[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-08-31
7
Medium Priority
?
441 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 160 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

649 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