2

This error was thrown by my code:

1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
1>C:\Users\thequantumforge\Desktop\scripts\Visual Studio 2013\Projects\newtonsmethod\x64\Debug\newtonsmethod.exe : fatal error LNK1120: 1 unresolved externals

The code is as follows:

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <cfloat>
#include <chrono>
using namespace std;
const long double h = LDBL_EPSILON;

long double equation(long double x) {
    return (pow(x, 3) - x + 1);
}

long double intercept(long double x) {
    // x_n+1 = xn - f(xn)/f'(xn)
    long double deriv = (equation(x + h) - equation(x)) / h;
    if (deriv == 0)
    {
        x += h;
        return (x - equation(x) / ((equation(x + h) - equation(x)) / h));
    }
    return (x - equation(x) / deriv);

int main() {...}

It worked in Code::Blocks using the C++11 compiler, so I'm not sure why it isn't working with Visual Studio 2015. I tried looking at other answers, but those were either unclear or were for other versions of Visual Studio. I did some research and found out that it's supposed to be caused by a misspelling of the main() function, but that doesn't seem to be the case. I tried declaring the function prototypes first then defining them after main(), but the result is the same.

  • 2
    Make sure that the project you created in `Visual Studio` is a `Win32 Console Application` and not a `Win32 Project`. – Mohamad Elghawi Feb 09 '16 at 14:08
  • How to mark duplicate? http://stackoverflow.com/questions/6626397 – oklas Feb 09 '16 at 14:10
  • Possible duplicate of [error LNK2019: unresolved external symbol \_WinMain@16 referenced in function \_\_\_tmainCRTStartup](http://stackoverflow.com/questions/6626397/error-lnk2019-unresolved-external-symbol-winmain16-referenced-in-function) – songyuanyao Feb 09 '16 at 14:23

1 Answers1

6

Change your solution into a console application in the linker => system section:

enter image description here

Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98