0

I'm having this Linker error: undefined reference to 'WinMain@16'

Here's the code:

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;



double dist(double array1[4], double array2[4])
{
    double Sum;
    double distance;
        
        
        
        
    for(int i=0;i<4;i++)
    {
        cout<<"Enter value of first coordinate";
        cin >> array1[i];
        cout<<"Enter value of second coordinate";
        cin >> array2[i];
        
        Sum = Sum + pow((array1[i]-array2[i]),2.0);
        distance = sqrt(Sum);
    }
        cout << "DISTANCE: " << distance;
    return distance;
}

I don't understand what part of the code is the cause of this error.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
pingboo23
  • 137
  • 1
  • 3
  • 15
  • Is this the full code? Where is `main`? –  Jan 15 '14 at 00:52
  • @Nabla Yes. Or did I just forgot something? Sorry, I'm having difficulties now in recalling to program with c++ – pingboo23 Jan 15 '14 at 00:54
  • 1
    You have no entry point. Every C++ program is required to have a function in global scope named `main` which will be the entry to the program. `WinMain` seems to be a Windows alternative to that. But none of them is surely not possible. See here: http://stackoverflow.com/questions/13871617/winmain-and-main-in-c-extended –  Jan 15 '14 at 00:55
  • please add it to your question code, have you tried `WinMain` instead, too? –  Jan 15 '14 at 01:02
  • Only `main` is required. Requiring `WinMain` is non-conforming. – chris Jan 15 '14 at 01:18
  • possible duplicate of [undefined reference to \`WinMain@16'](http://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16) – chris Jan 15 '14 at 01:19
  • Before posting a question here, please do a search first for existing questions and answers, particularly when you have a specific error message on which to search. Chances are quite good that the question has been asked (and answered) here previously. – Ken White Jan 15 '14 at 01:47
  • @chris WinMain is the entry point for Windows programs. main is in the windows library that you link with your program - the same way that MFC, QT and almost every other GUI library does it. There *is* a main function - it just isn't written by the user of the Windows library. – Jerry Jeremiah May 12 '21 at 21:30
  • @pingboo23 `main` is the the e ntry point for Windows console programs. `WinMain` is the entry point for Windows GUI programs. You are obviously compiling a program for the Windows GUI subsystem so you need to provide that function. Here is something to read: https://learn.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point – Jerry Jeremiah May 12 '21 at 21:32
  • @JerryJeremiah, The top answer in the question I linked goes into a lot more detail on what I think I was getting at (you'll have to forgive my memory). Specifically that it's quite possible to receive this error when a plain `main` function will work (and when not compiling for a GUI subsystem) and that even MSVC's linker allows `WinMain` to not be required. If any of that sounds suspect, please read the answer in the linked question. In addition, the title of _this_ question mentions `ld`, which is not Microsoft's linker, making GCC behaviour here quite relevant. – chris May 13 '21 at 03:52

0 Answers0