Why won't this GLUT program compile? Am I missing libraries or headers?
I've just started using Linux (Mint 11), and recently, I decided to take up OpenGL programming as a hobby. I'm finding the code and techniques relatively simple enough, however, I'm having a hard time trying to get all the resources in the right place. The code is:
#include <stdlib.h>
#include <stdio.h>
#include <GL/glew.h>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
static int make_resources(void)
{
return 1;
}
static void update_fade_factor(void)
{
}
static void render(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(400, 300);
glutCreateWindow("Hello World");
glutDisplayFunc(&render);
glutIdleFunc(&update_fade_factor);
glewInit();
if (!GLEW_VERSION_2_0) {
fprintf(stderr, "OpenGL 2.0 not available\n");
return 1;
}
if (!make_resources()) {
fprintf(stderr, "Failed to load resources\n");
return 1;
}
glutMainLoop();
return 0;
}
When I compile, I get the following messages
../../Libraries/glut-3.7/lib/glut/libglut.so||undefined reference to `glXQueryChannelRectSGIX'|
../../Libraries/glut-3.7/lib/glut/libglut.so||undefined reference to `glXChannelRectSyncSGIX'|
../../Libraries/glut-3.7/lib/glut/libglut.so||undefined reference to `glXChannelRectSGIX'|
../../Libraries/glut-3.7/lib/glut/libglut.so||undefined reference to `glXQueryChannelDeltasSGIX'|
../../Libraries/glut-3.7/lib/glut/libglut.so||undefined reference to `glXBindChannelToWindowSGIX'|
||=== Build finished: 5 errors, 0 warnings ===|
Looking online told me that I'm probably not including the right libraries (presumably libX), however I'm unsure of where I can find them, If they're even the right ones to use. I've already tried linking /usr/lib/X86_64-linux-gnu/libX11.so, /usr/lib/X11 contains neither library files nor a /lib directory, and I'm certain that the lib11-dev package is installed. What am I doing wrong?
INFO:
OS: Linux Mint 11 IDE: Code::blocks 10.05 Following this tutorial. Note: I cannot find the x11r6 directories it refers to.开发者_Go百科be sure you have installed libglew-dev and freeglut3-dev with
sudo apt-get install libglew-dev freeglut3-dev
and then link to this libs in your Makefile or compile command with
-lglut -lGLEE
for example
g++ -lglut -lGLEW -o test main.cpp
(this is how I compiled your example)
In Linux you don't specify the paths to the library files to link to, but only the library names. The linker knows a list of paths were to look for in the libraries. Also libraries contain references to all the other libraries they require. To compile/link a GLUT programm the following command line is usually sufficient
gcc -o ${BINARY} ${SOURCE_FILES_OR_OBJECTS} -lglut
精彩评论