Search code examples
c++linuxopenglglewfreeglut

unidentified reference to glutInit


I tried to compile a basic OpenGL program, simply just a blank window. I'm using CodeLite with the g++ compiler on Linux Mint 18.1 (Ubuntu 16.04 LTS).

The code so far is:

#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>

int main(int argc, char **argv)
{
    glutInit(&argc, argv);

    printf("hello world\n");
    return 0;
}

At first my compiler (G++ in CodeLite) gave the error

/home/USER/Projects/CodeLite/Graphical/main.cpp:7: undefined reference to `glutInit'

I downloaded all the up to date GLEW and GLUT includes from their respective websites and unpacked them to /usr/include/GL, I edited the project settings linker like this.

Now it gives the error message:

/usr/bin/ld: cannot find -lglut
Makefile:4: recipe for target 'All' failed

What can I do to fix this?


Solution

  • You should install the libraries from the package manager instead: libglew-dev, freeglut3-dev, libgl1-mesa-dev and libglu1-mesa-dev. The includes and binary files will be placed in the appropriate location.

    If the linker cannot find the .so files, locate them with dpkg -L freeglut3-dev and add this directory in the linker command line

    g++ -L/path/to/libglut.so *.o -o programname