我正在使用Ubuntu 14.04上的代码块开发一个关于OpenGl的项目,虽然我确信我已经下载了Gl / glut库,这是我在编译代码时遇到的错误:
||=== Build: Debug in CAnko (compiler: GNU GCC Compiler) ===|
obj/Debug/Desktop/minesweeper/main.o||In function `display()':|
/home/canonder/Desktop/minesweeper/main.cpp|9|undefined reference to `glClear'|
/home/canonder/Desktop/minesweeper/main.cpp|11|undefined reference to `glutSwapBuffers'|
obj/Debug/Desktop/minesweeper/main.o||In function `mouse(int, int, int, int)':|
/home/canonder/Desktop/minesweeper/main.cpp|27|undefined reference to `glutPostRedisplay'|
obj/Debug/Desktop/minesweeper/main.o||In function `main':|
/home/canonder/Desktop/minesweeper/main.cpp|33|undefined reference to `glutInit'|
/home/canonder/Desktop/minesweeper/main.cpp|34|undefined reference to `glutInitDisplayMode'|
/home/canonder/Desktop/minesweeper/main.cpp|35|undefined reference to `glutInitWindowSize'|
/home/canonder/Desktop/minesweeper/main.cpp|36|undefined reference to `glutInitWindowPosition'|
/home/canonder/Desktop/minesweeper/main.cpp|37|undefined reference to `glutCreateWindow'|
/home/canonder/Desktop/minesweeper/main.cpp|38|undefined reference to `glClearColor'|
/home/canonder/Desktop/minesweeper/main.cpp|39|undefined reference to `glMatrixMode'|
/home/canonder/Desktop/minesweeper/main.cpp|40|undefined reference to `glLoadIdentity'|
/home/canonder/Desktop/minesweeper/main.cpp|41|undefined reference to `glOrtho'|
/home/canonder/Desktop/minesweeper/main.cpp|42|undefined reference to `glutDisplayFunc'|
/home/canonder/Desktop/minesweeper/main.cpp|43|undefined reference to `glutMouseFunc'|
/home/canonder/Desktop/minesweeper/main.cpp|44|undefined reference to `glutMainLoop'|
obj/Debug/Desktop/minesweeper/painter.o||In function `Painter::drawClosedField(int, int)':|
/home/canonder/Desktop/minesweeper/painter.cpp|9|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|10|undefined reference to `glBegin'|
/home/canonder/Desktop/minesweeper/painter.cpp|11|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|12|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|13|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|14|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|15|undefined reference to `glEnd'|
/home/canonder/Desktop/minesweeper/painter.cpp|16|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|17|undefined reference to `glBegin'|
/home/canonder/Desktop/minesweeper/painter.cpp|18|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|19|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|20|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|21|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|22|undefined reference to `glEnd'|
/home/canonder/Desktop/minesweeper/painter.cpp|23|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|24|undefined reference to `glBegin'|
/home/canonder/Desktop/minesweeper/painter.cpp|25|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|26|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|27|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|28|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|29|undefined reference to `glEnd'|
obj/Debug/Desktop/minesweeper/painter.o||In function `Painter::drawOpenedField(int, int, int)':|
/home/canonder/Desktop/minesweeper/painter.cpp|40|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|43|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|46|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|49|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|52|undefined reference to `glColor3f'|
obj/Debug/Desktop/minesweeper/painter.o:/home/canonder/Desktop/minesweeper/painter.cpp|55|more undefined references to `glColor3f' follow|
obj/Debug/Desktop/minesweeper/painter.o||In function `Painter::drawOpenedField(int, int, int)':|
/home/canonder/Desktop/minesweeper/painter.cpp|64|undefined reference to `glRasterPos2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|65|undefined reference to `glutBitmap9By15'|
/home/canonder/Desktop/minesweeper/painter.cpp|65|undefined reference to `glutBitmapCharacter'|
obj/Debug/Desktop/minesweeper/painter.o||In function `Painter::drawFlag(int, int)':|
/home/canonder/Desktop/minesweeper/painter.cpp|71|undefined reference to `glColor3f'|
/home/canonder/Desktop/minesweeper/painter.cpp|72|undefined reference to `glBegin'|
/home/canonder/Desktop/minesweeper/painter.cpp|73|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|74|undefined reference to `glVertex2f'|
/home/canonder/Desktop/minesweeper/painter.cpp|75|undefined reference to `glVertex2f'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
以下是整个主要代码:
#include "game.hpp"
#include "painter.hpp"
#include <GL/glut.h>
Game game;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
game.draw();
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
if (state == GLUT_UP)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
game.open(x / Painter::CELL_WIDTH, y / Painter::CELL_HEIGHT);
break;
case GLUT_RIGHT_BUTTON:
game.mark(x / Painter::CELL_WIDTH, y / Painter::CELL_HEIGHT);
break;
}
glutPostRedisplay();
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(Game::WIDTH * Painter::CELL_WIDTH, Game::HEIGHT * Painter::CELL_HEIGHT);
glutInitWindowPosition(100, 120);
glutCreateWindow("MineSweeper");
glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Game::HEIGHT * Painter::CELL_HEIGHT, Game::WIDTH * Painter::CELL_WIDTH, 0, -1.0, 1.0);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
感谢任何帮助,谢谢。