所以我一直在关注教程,当我尝试编译以下代码时:
#include <glut.h>
#include <iostream>
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Test GLUT App");
glutDisplayFunc(render); // render
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop(); // initialization finished. start rendering
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.5, 0.2, 0.9);
glVertex2f(-0.5, -0.5);
glColor3f(0.1, 0.2, 0.5);
glVertex2f(0.0, -0.5);
glColor3f(0.3, 0.9, 0.7);
glVertex2f(0.0, 0.5);
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 27)
{
exit(0);
}
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_RIGHT_BUTTON)
{
exit(0);
}
}
我突然发现 3次错误:
错误1错误C2381:'退出':重新定义; __declspec(noreturn)不同于c:\ program files(x86)\ microsoft visual studio 10.0 \ vc \ include \ stdlib.h 353
错误2错误C3861:'退出':找不到标识符.... main.cpp 45
错误3错误C3861:'退出':找不到标识符.... main.cpp 53
有谁知道为什么会出现此错误?我正在使用VS2010。
答案 0 :(得分:7)
答案 1 :(得分:2)
如果您的Visual Studio抛出构建错误,说明IntelliSense未识别&#39;退出&#39;那么你必须包括 process.h
答案 2 :(得分:0)
尝试将using namespace std
添加到顶部。我不确定这是否会解决它,但我之前有类似的错误并修复了它。祝你好运。
答案 3 :(得分:0)
你需要将header简单地声明为work,在我的comp中工作
#include <stdlib.h>
#include <cstdlib>
#include <glut.h>
#include <iostream>