Why can't I get the most basic WSTP demo (addtwo.c) to build and link?

I am trying to use WSTP and started with the addtwo demo. I converted the template file to C using wsprep, then in Visual Studio 2013, added that, the addtwo.c file, the wstp libraries and the header file to the project. It compiled as a console app but would not link, reporting that it could not find main().

The error can be seen here:

What am I doing wrong?

Try changing line 25 of addtwo.c

 #if WINDOWS_MATHLINK

to

 #if 0

That enabled it to link, but it then crashes at runtime.

Any suggestions?

Maybe this part of the documentation is relevant

As of Version 10.0 of the Wolfram System, the Wolfram System installer no longer installs the WSTP dynamic libraries in the Windows system directory. As a WSTP developer, you will need to place the WSTP dlls in a location on your system where your applications can find the dlls.

I don’t think that’s it; I have copies of the DLLs in the binary directory. Without them, the binary won’t run when double-clicked upon but with them, it runs then crashes. The behavior from within Mathematica seems to mirror the behavior with the DLL in place, so it looks like the system is seeing the DLL.

Interesting, I just followed the same procedure in VS 2013 and both the Win32 and x64 addtwo.exe ran fine. Maybe clicking on the ‘Debug’ button would yield some clue?

Reporting back a year later – Among the problems here, (1) the project should never have been build as a console app; WSTP programs should be built as Win32 apps, and (2) I was including all sorts of libraries that I didn’t need. Only wstp32i4.lib was needed. I have created a number of useful WSTP since.