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

发布于 2024-11-26 12:42:54 字数 1007 浏览 1 评论 0原文

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

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

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

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

编辑: 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;
}

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).

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.

EDIT: The main() method:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼泪都笑了 2024-12-03 12:42:54

SDL_main.h 是从 SDL.h 自动包含的,所以你总是得到令人讨厌的#define。

只要写:

#include <SDL.h>
#undef main

它应该可以正常工作

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

Just write:

#include <SDL.h>
#undef main

And it should work fine

无妨# 2024-12-03 12:42:54

另一种选择实际上是使用常用参数定义您自己的 main ,

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

这应该可以消除错误。

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

(void)argc;
(void)args;

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

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;
伤感在游骋 2024-12-03 12:42:54

SDL 文档中的默认解决方案:

tl;dr:

#define SDL_MAIN_HANDLED
#include "SDL.h"

完整示例:

使用此函数可以避免在不使用时 SDL_Init() 失败
SDL_main() 作为入口点。

#define SDL_MAIN_HANDLED
#include "SDL.h"

int main(int argc, char *argv[])
{
    SDL_SetMainReady();
    SDL_Init(SDL_INIT_VIDEO);

    ...

    SDL_Quit();

    return 0;
}

来源:https://wiki.libsdl.org/SDL_SetMainReady

The default solution from SDL documentation:

tl;dr:

#define SDL_MAIN_HANDLED
#include "SDL.h"

full example:

Use this function to circumvent failure of SDL_Init() when not using
SDL_main() as an entry point.

#define SDL_MAIN_HANDLED
#include "SDL.h"

int main(int argc, char *argv[])
{
    SDL_SetMainReady();
    SDL_Init(SDL_INIT_VIDEO);

    ...

    SDL_Quit();

    return 0;
}

Source: https://wiki.libsdl.org/SDL_SetMainReady

多彩岁月 2024-12-03 12:42:54

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

#define main SDL_main

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

#define main SDL_main
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文