简体   繁体   中英

SFML linker error: unresolved external symbol _WinMain@16, Visual Studio 2012

I was able to get tutorial #1 to compile fine. But I can't get the 2nd one to compile.

When you do new -> Project, maybe one of those settings are interfering? Pretty sure I did empty project, else console.

What's wrong? compile error:

Error   1   error LNK2019: unresolved external symbol _WinMain@16 referenced in function
___tmainCRTStartup  C:\...\02-videomode-iterate\MSVCRTD.lib(crtexew.obj)    02-videomode-iterate
Error   2   error LNK1120: 1 unresolved externals   C:\...\Debug\02-videomode-iterate.exe   02-videomode-iterate

entire source:

#include <SFML/Window.hpp>

int main()
{
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML-tut: 02");

    bool Running = true;
    while (Running)
    {
        App.Display();
    }

    return EXIT_SUCCESS;
}

Project settings:

include dir, lib: dir set correctly.

c++ -> preprocessor -> preprocessor definitions:

SFML_DYNAMIC

linker -> input

tried: sfml-window.lib and sfml-window-d.lib ( visual studio seems to always use debug mode at start? but tutorial #1 only worked when I didn't use -d version.

subsystem:

/SUBSYSTEM:WINDOWS

When you set the /SUBSYSTEM:WINDOWS flag, the linker will look for a WinMain function rather than the conventional main . You have two options:

  1. Change to /SUBSYSTEM:CONSOLE . You will get an annoying (or perhaps helpful) console window, which you can get rid of with FreeConsole .
  2. Change main to WinMain with the following signature:

     int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); 

    Unless you need to access argc and argv , this change shouldn't cause too much trouble.


Edit: Perhaps this is worth a look too (copied from the second tutorial):

Under Windows operating systems, you may have created a "Windows Application" project, especially if don't want the console to show up. In such case, to avoid replacing main by WinMain, you can link with SFML_Main static library and keep a standard and portable main entry point.

So, I suppose that boils down to adding sfml-main.lib (or similar) to the list of libraries to link with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM