Solved

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

Posted on 2004-08-31
7
387 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
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now