在Visual Studio 2010中使用OpenGL-错误LNK2019:函数___tmainCRTStartup中引用了无法解析的外部符号_WinMain @ 16 [英] Using OpenGL in Visual Studio 2010 - error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

查看:177
本文介绍了在Visual Studio 2010中使用OpenGL-错误LNK2019:函数___tmainCRTStartup中引用了无法解析的外部符号_WinMain @ 16的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio中编译此OpenGL程序.阅读大量文章后,我已经正确设置了它.我已将正确的库添加到链接器的其他依赖项.但是我收到此错误:

I am compiling this OpenGL program in Visual Studio. I have set it up properly, after reading numerous articles. I have added the correct libraries to linker's additional dependencies. However I am getting this error:

错误LNK2019:函数_ _tmainCRTStartup

error LNK2019: unresolved external symbol WinMain@16 referenced in function __tmainCRTStartup

我正在编译的代码是:

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void init(void) 
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_FLAT);
}

void display(void)
{
   glClear (GL_COLOR_BUFFER_BIT);
   glColor3f (1.0, 1.0, 1.0);
   glLoadIdentity ();             /* clear the matrix */
           /* viewing transformation  */
   gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   glScalef (1.0, 2.0, 1.0);      /* modeling transformation */ 
   glutWireCube (1.0);
   glFlush ();
}

void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
   glMatrixMode (GL_MODELVIEW);
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (500, 500); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display); 
   glutReshapeFunc(reshape);
   glutMainLoop();
   return 0;
}

推荐答案

Windows中有两种可执行文件:

There are two kind of executables in Windows:

  1. 控制台
  2. GUI(Windows)

唯一的区别是,控制台可执行文件会自动打开控制台窗口,而C/C ++ CRT运行时会将标准的stdout/stdin/stderr句柄关联到该窗口.否则,这两种可执行文件类型之间没有区别-两者都可以创建新的Windows,绘制事物,使用OpenGL等...

Only difference is that Console executables automatically opens console window, and C/C++ CRT runtime associates standart stdout/stdin/stderr handles to go to this window. Otherwise there are no differences between these two executable types - both can create new Windows, draw things, use OpenGL, etc...

在visual Studio中,如果您创建控制台应用程序-那么它期望您的入口点被称为主".但是对于GUI应用程序,它期望入口点函数被称为"WinMain".因此,如果您不想在应用程序启动时看到控制台窗口,则有两种选择:

In visual Studio, if you create Console application - then it expects your entry point to be called "main". But for GUI application it expects entry point function to be called "WinMain". So you have two options if you don't want to see Console window when your application starts:

  1. 更改项目链接器设置以指示您正在构建GUI应用程序(项目属性->链接器->系统-> Subystem = Windows).这将需要将您的入口点函数称为WinMain: http://msdn.microsoft.com/zh-我们/library/ff381406.aspx
  2. 指示链接器,即使您想使用GUI应用程序,但也希望将您的入口点称为"main".您可以在项目属性->链接器->高级->入口点= mainCRTStartup中执行此操作.不要放在主要的地方.放置mainCRTStartup-它是特殊的C/C ++ CRT函数,它会初始化标准C库并自动调用您的main函数.以下是有关此设置的文档: http://msdn.microsoft.com/en-us/library/f9t8842e .aspx
  1. Change project linker settings to indicate you are building GUI application (Project Properties -> Linker -> System -> Subystem = Windows). This will require your entry point function to be called WinMain: http://msdn.microsoft.com/en-us/library/ff381406.aspx
  2. Indicate to linker that even if you want to use GUI application, but you want your entry point to be called "main". You can do that in Project Properties -> Linker -> Advanced -> Entry Point = mainCRTStartup. Don't put there main. Put there mainCRTStartup - it is special C/C++ CRT function that initializes standard C library and calls your main function automatically. Heres the documentation about this setting: http://msdn.microsoft.com/en-us/library/f9t8842e.aspx

使用第二个选项意味着,您可以使用GLUT,将入口点称为"main",并且在启动时未打开控制台窗口.

Using second options means, that you can use GLUT, have your entry point called "main" and have no Console window opened at startup.

这篇关于在Visual Studio 2010中使用OpenGL-错误LNK2019:函数___tmainCRTStartup中引用了无法解析的外部符号_WinMain @ 16的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆