代码如下,挺简单的一个
#include<gl/glut.h>
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
GLfloat vertices[3][2]={{0,0},{25,50},{50,0}};
int i,j,k;
int rand();
GLfloat p[2]={7.5,5.0};
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(k=0;k<5000;k++)
{
j=rand()%3;
p[0]=(p[0]+vertices[j][0])/2.0;
p[1]=(p[1]+vertices[j][1])/2.0;
glVertex2fv(p);
}
glEnd();
glFlush();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("sdddd");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}编译错误:
正在链接...
1>src.obj : error LNK2028: 无法解析的标记(0A000001) "int __cdecl rand(void)" (?rand@@$$FYAHXZ),该标记在函数 "void __cdecl display(void)" (?display@@$$FYAXXZ) 中被引用
1>src.obj : error LNK2019: 无法解析的外部符号 "int __cdecl rand(void)" (?rand@@$$FYAHXZ),该符号在函数 "void __cdecl display(void)" (?display@@$$FYAXXZ) 中被引用
1>G:\编程\图形学\Debug\图形学.exe : fatal error LNK1120: 2 个无法解析的外部命令
这时为什么?为什么?