C++ 错误 LNK2019:函数 ___tmainCRTStartup 中引用了未解析的外部符号 _main,但这一次不是 Windows/控制台问题!

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6847360/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:46:08  来源:igfitidea点击:

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup, but this time it's NOT a Windows/Console problem!

c++openglsdllnk2019

提问by OddCore

So, the infamous error is back. The project is complaining that it can't find the main() method (that's what the error means, right).

所以,臭名昭著的错误又回来了。该项目抱怨它找不到 main() 方法(这就是错误的含义,对)。

However I do have a main, and my project is a Console project, as it should be. It worked before, so I know it's not that.

但是,我确实有一个主项目,而我的项目应该是一个控制台项目。它以前有效,所以我知道不是那样。

Also, the project has too many classes and files for me to post them all, so I will post any classes you need by request.

此外,该项目有太多的类和文件,我无法将它们全部发布,因此我将根据您的要求发布您需要的任何类。

It's a C++, OpenGL and SDL game on Visual Studio 2010. It's not a problem of any of the libraries, as it was working fine before it suddenly and inexplicably showed this linker error.

它是 Visual Studio 2010 上的 C++、OpenGL 和 SDL 游戏。这不是任何库的问题,因为它在突然莫名其妙地显示此链接器错误之前运行良好。

EDIT: The main() method:

编辑: main() 方法:

int main(int argc, char **argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA);
 glutCreateWindow("Game");

 glEnable(GL_DEPTH_TEST);
 glEnable(GL_NORMALIZE);
 glEnable(GL_COLOR_MATERIAL);
 glEnable(GL_BLEND);
 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

 g = Game();
 glutInitWindowSize(g.getScreenWidth(), g.getScreenHeight());
 //glutPositionWindow(1280, 50);

 // Callbacks
 glutDisplayFunc(handleRedraw);
 glutReshapeFunc(handleResize);
 glutMouseFunc(handleMouseClicks);
 glutPassiveMotionFunc(handleMouseOvers);
 glutKeyboardFunc(handleKeyboardEvents);
 glutTimerFunc(50, moveItemToInventory, 0);

 glutMainLoop();

 return 0;
}

回答by rodrigo

SDL_main.h is included automatically from SDL.h, so you always get the nasty #define.

SDL_main.h 是从 SDL.h 自动包含的,因此您总是会遇到令人讨厌的 #define。

Just write:

写就好了:

#include <SDL.h>
#undef main

And it should work fine

它应该可以正常工作

回答by ForceMagic

Another option would actually to define your own main with the usual parameters

另一种选择实际上是用通常的参数定义你自己的 main

int main(int argc, char *args[])
{
    // Your code here
}

That should get rid of the error.

那应该摆脱错误。

Then if you don't use those parameters and you also want to get rid of the compiler warning you could do that trick in your main function.

然后,如果您不使用这些参数,并且还想摆脱编译器警告,则可以在主函数中使用该技巧。

(void)argc;
(void)args;

回答by juwens

回答by tibur

The culprit is likely to be SDL_main.h. Check that you don't include that file, there is a nasty define there:

罪魁祸首很可能是SDL_main.h。检查您是否不包含该文件,那里有一个讨厌的定义:

#define main SDL_main