2012-10-19 96 views
1

我能够得到tutorial #1编译好。但我无法获得the 2nd one的编译。SFML链接器错误:无法解析的外部符号_WinMain @ 16,Visual Studio 2012

当你做新的 - >项目,也许这些设置之一是干扰?很确定我做了空项目,否则控制台。

怎么了? 编译错误:

Error 1 error LNK2019: unresolved external symbol [email protected] 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 

整个源:

#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; 
} 

项目设置:

include dir, lib: dir set correctly.

C++ - >预处理器 - >预处理器定义:

SFML_DYNAMIC

链路呃 - >输入

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:WINDOWS

回答

1

当您设置/SUBSYSTEM:WINDOWS标志,连接器会寻找一个WinMain函数,而不是传统的main。您有两种选择:

  1. 更改为/SUBSYSTEM:CONSOLE。你会得到一个恼人的(或者可能有用的)控制台窗口,你可以用FreeConsole摆脱。
  2. 变化mainWinMain具有以下签名:

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

    除非你需要访问argcargv,这种变化应该不会造成太大的麻烦。


编辑:也许这是值得一太(从第二个教程复制):

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.

所以,我想这可以归结为增加sfml-main.lib(或类似)的链接的库列表。

相关问题