[英]SFML linker error: unresolved external symbol _WinMain@16, Visual Studio 2012
I was able to get tutorial #1 to compile fine. 我能够获得教程#1进行编译。 But I can't get the 2nd one to compile. 但是我无法编译第二个 。
When you do new -> Project, maybe one of those settings are interfering? 当您新建-> Project时, 这些设置之一可能会干扰吗? 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. include dir,lib:dir设置正确。
c++ -> preprocessor -> preprocessor definitions: C ++->预处理程序->预处理程序定义:
SFML_DYNAMIC SFML_DYNAMIC
linker -> input 链接器->输入
tried:
sfml-window.lib
andsfml-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. 尝试过:sfml-window.lib
和sfml-window-d.lib
(Visual Studio似乎总是在开始时使用调试模式?但是,教程#1仅在我不使用-d版本时有效。
subsystem: 子系统:
/SUBSYSTEM:WINDOWS /子系统:WINDOWS
When you set the /SUBSYSTEM:WINDOWS
flag, the linker will look for a WinMain
function rather than the conventional main
. 设置/SUBSYSTEM:WINDOWS
标志时,链接器将查找WinMain
函数而不是常规的main
。 You have two options: 您有两种选择:
/SUBSYSTEM:CONSOLE
. 更改为/SUBSYSTEM:CONSOLE
。 You will get an annoying (or perhaps helpful) console window, which you can get rid of with FreeConsole
. 您将获得一个烦人的(或可能有用的)控制台窗口,您可以使用FreeConsole
摆脱FreeConsole
。 Change main
to WinMain
with the following signature: 使用以下签名将main
更改为WinMain
:
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. 除非您需要访问argc
和argv
,否则此更改不会引起太多麻烦。
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. 在Windows操作系统下,您可能已经创建了“ Windows应用程序”项目,尤其是在不想显示控制台的情况下。 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. 在这种情况下,为避免用WinMain替换main,可以与SFML_Main静态库链接,并保留一个标准且可移植的main入口点。
So, I suppose that boils down to adding sfml-main.lib
(or similar) to the list of libraries to link with. 因此,我想归结为将sfml-main.lib
(或类似文件)添加到要链接的库列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.