[Okta Webinar] Learn how to a build a cloud-first strategyRegister 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
?
454 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
4 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

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

834 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