C++ SDL2:LNK1561:必须定义入口点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18672303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SDL2: LNK1561: entry point must be defined
提问by Dmitry
I want to compile this code:
我想编译这段代码:
#include <SDL.h>
int main(int argc, char* argv[]) {
return 0;
}
But it can't be linked: Error 1 error LNK1561: entry point must be defined
但是不能链接: Error 1 error LNK1561: entry point must be defined
There is some strange code in this library: http://hg.libsdl.org/SDL/file/75726efbf679/include/SDL_main.h
这个库中有一些奇怪的代码:http: //hg.libsdl.org/SDL/file/75726efbf679/include/SDL_main.h
#define main SDL_main
Also I added SDL2.lib;SDL2main.lib
to Project Settings => Linker => Input.
我还添加SDL2.lib;SDL2main.lib
到项目设置 => 链接器 => 输入。
What can I do to run this project?
VS 2012 SP3, empty C++ project.
我可以做什么来运行这个项目?
VS 2012 SP3,空的 C++ 项目。
回答by 4pie0
According to this threadon Dream.In.Code:
根据Dream.In.Code上的这个线程:
Right click on project name -> Properties -> Expand Linker tab -> System -> SubSystem: make sure that it is
Console (/SUBSYSTEM:CONSOLE)
右键单击项目名称 -> 属性 -> 展开链接器选项卡 -> 系统 -> 子系统:确保它是
Console (/SUBSYSTEM:CONSOLE)
Alternatively, if you want to hide the console window or are debugging a multithreaded application, you should set the SubSystem to Window (/SUBSYSTEM:WINDOW)
instead.
或者,如果要隐藏控制台窗口或正在调试多线程应用程序,则应将 SubSystem 设置为Window (/SUBSYSTEM:WINDOW)
。
回答by dpiron
I have found that setting /SUBSYSTEM:CONSOLEis only half of the solution. The second half is to add SDL_MAIN_HANDLED
to your additional defines. The clue I used to resolve this can be found in SDL_main.h. Setting SDL_MAIN_HANDLED
tell the SDL header files that you've already provided a main
function and do not wish for it to redefine its own entry point.
我发现设置/SUBSYSTEM:CONSOLE只是解决方案的一半。后半部分是添加SDL_MAIN_HANDLED
到您的附加定义。我用来解决这个问题的线索可以在SDL_main.h 中找到。设置SDL_MAIN_HANDLED
告诉 SDL 头文件您已经提供了一个main
函数并且不希望它重新定义它自己的入口点。
回答by Gustavo Maciel
DON'T#undef main
! while its a really bad practice on the SDL side to redefine it, they have good reasons: WinMain
is defined on the library side and used to run some init code, helping with compatibility issues. (even more when using different SDL implementations, like Steam's or porting to other platforms like Android)
不要#undef main
!虽然在 SDL 端重新定义它是一个非常糟糕的做法,但它们有很好的理由:WinMain
在库端定义并用于运行一些初始化代码,帮助解决兼容性问题。(在使用不同的 SDL 实现时更是如此,例如 Steam 或移植到 Android 等其他平台)
So what should you do? When on Windows, you should always include SDL2main.lib
before SDL2.lib
and make sure your main is in the format:
那你该怎么办?在 Windows 上,您应该始终包含SDL2main.lib
之前SDL2.lib
并确保您的主要格式为:
int main(int argc, char* argv[]) // CORRECT
void main(int argc, char* argv[]) // WRONG
int main(int, char**) // MAY BE CORRECT
Source: SDL2 Windows FAQ
回答by ?ukasz Mleczko
As a tinky_winkiwrote
正如tinky_winki所写
Right click on project name -> Properties -> Expand Linker tab -> System -> SubSystem: make sure that it is Console (/SUBSYSTEM:CONSOLE)
右键单击项目名称 -> 属性 -> 展开链接器选项卡 -> 系统 -> 子系统:确保它是控制台 (/SUBSYSTEM:CONSOLE)
But if you don't expect console with window simply use, /SUBSYSTEM:WINDOWS
但是,如果您不希望带窗口的控制台简单地使用,/SUBSYSTEM:WINDOWS
回答by Micha? Rugbu?
Project >> Properties >> Linker >> Advanced >> entry point = main and apply
项目>>属性>>链接器>>高级>>入口点=主要和应用
回答by Tawanda Chiteshe
i just go in sdl_main.h and flip #define main sdl_main
我只是进入 sdl_main.h 并翻转 #define main sdl_main
to
到
define sdl_main main
定义 sdl_main main
it worked but this is bad hooray to short term solutions
它有效,但这对短期解决方案来说是糟糕的万岁