2

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.

Louie
  • 75
  • 1
  • 6
  • 1
    It would have been nice if you have provided a command used to compile and link. –  Jul 27 '11 at 21:48
  • I'm simply using the "build" option in code::blocks. However, I'm unsure of how to find what is issued to the compiler in this IDE, but if I helps, I started by making a blank project, then changed it to a "GUI application" in the build settings. I've added libGL, libGLU, libGLEW, libGLUT, and /usr/lib/x86_64-linux-gnu/libX11.so. the compiler options show no other options checked other than the one to suppress warnings. – Louie Jul 27 '11 at 22:05

2 Answers2

3

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)

ben
  • 1,819
  • 15
  • 25
  • 1
    on codeblocks do this: right-click on project -> build options -> select your project name (not only a target) in the upper left -> Linker settings tab -> Click on Add -> add "glut" and "GLEW" to the linker – ben Jul 27 '11 at 22:15
  • Alright, that seemed to make it work (adding -lglut and -lGLEW). I compiled and installed the regular non GNU GLUT prior, is that what was generating the problems? – Louie Jul 27 '11 at 22:21
  • possible, don't know what you installed first, maybe the libs were to old or to new or something else. it's always better to try the libs first which comes through your package manager. – ben Jul 27 '11 at 22:26
1

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
datenwolf
  • 159,371
  • 13
  • 185
  • 298