Menu

OpenGL: How to find the glut.h header file?

Jarvis Loh
2008-05-05
2012-09-26
  • Jarvis Loh

    Jarvis Loh - 2008-05-05

    I am a newbie (well, i know that is cliche). I intend to do some simulation using OpenGL. Below is a shorter version of the program (just to test):

    include <stdio.h>

    include <cmath>

    include <GL/gl.h>

    define PI 3.1415926535898

    int no;

    int main(void) {
    void draw(void);
    draw();
    printf("Pause");
    scanf("%d",&no);
    return 0;
    }

    void draw() {
    GLint circle_points=100;
    glBegin(GL_LINE_LOOP);
    for (int i=0;i<circle_points;i++) {
    float angle=2PIi/circle_points;
    glVertex2f(cos(angle), sin(angle));
    }
    glEnd();
    }

    I understand that I hav to include the glut.h header file, but when i #include that, and compile, an error states that there is no such header file.

    The debug log for the above is:

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Dev-Cpp\TESTING.cpp" -o "C:\Dev-Cpp\TESTING.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
    C:\DOCUME~1\lohg0003\LOCALS~1\Temp/ccaecaaa.o(.text+0x6c): In function Z4drawv': C:/Dev-Cpp/TESTING.cpp:19: undefined reference toglBegin@4'
    C:\DOCUME~1\lohg0003\LOCALS~1\Temp/ccaecaaa.o(.text+0xbf):C:/Dev-Cpp/TESTING.cpp:22: undefined reference to glVertex2f@8' C:\DOCUME~1\lohg0003\LOCALS~1\Temp/ccaecaaa.o(.text+0xce):C:/Dev-Cpp/TESTING.cpp:24: undefined reference toglEnd@0'
    collect2: ld returned 1 exit status

    Execution terminated

    I apologise for the long post, and i appreciate any help or advice rendered. Thanks!

     
    • cpns

      cpns - 2008-05-06

      >> Am I doing the correct thing, in order to
      >> link the OpenGL library?

      Your log suggests that you added it to the compiler options rather than the linker options. However the options set in Tools|Compiler Options|General are applied to all projects. You are better off adding such options to Project|Project options|Compiler|Linker (note I am giving these dialog references from memory at the moment, so you may have to 'explore' - its a tab with three boxes for C compiler, C++ compiler, and linker, and a button for browsing for libraries or object files).

      The log you posted shows that it is no longer compiling. This is not due to the addition of the -l option, you must have changed the code, because your first log clearly indicated that compilation was successful merely by the fact that it was linking. Fix one problem at a time and don't move the goalposts - unless you post the code as well.

      >> I dun quite get what u mean. Is it possible
      >> for you to put it in another way?
      My directions were intended to be generally applicable to the GNU compiler rather than specific to Dev-C++ dialogs - in Dev-C++ there are several ways of affecting teh compiler/linker invocation. In Project|Project options|Compiler there is a button for adding object files and libraries. This specifies the full path to the linker. Alternatively add the directory path to Project|Project options|Directories|Libraries (if it is not already a default - which in teh case of libopengl32.a it is), and use a -l<lib> option.

      Whenever you make any of these changes, look at the compile log to see how it affected the compiler/linker command lines. Note that to get a full log you should use Rebuild-All.

      >> I hav downloaded the 3 files (glut.h into C:\Program Files\Microsoft
      >> Visual Studio\VC98\Include\GL , glut32.lib into C:\Program Files\ >> Microsoft Visual Studio\VC98\Lib

      Make up your mind, are you using VC++ or Dev-C++ !? Since the log indicates that glut.h is in "C:/Dev-Cpp/include/GL/" the above is obviously not entirely true. Moreover Microsoft export libraries (glut32.lib) are not compatible with MinGW/GCC. You cannot use that directly. However your problem is with glut.h. Did you check out the GLUT advise in the "read first" thread as I suggested and Wayne repeated!?

      If you choose to use VC++ I suggest using the superior (and free) VC++2008 Express.

      >> Are the locations I hav copied the 3 files correct?
      You can put them where you like so long as teh paths are specified with -I<incpath> and -L<libpath> switches. The evidence suggests you did not put them where you have said, and you have not specified those paths to the compiler in any case.

      I suggest that you put third party libraries in their own paths separate from the Dev-C++ installation rather than dumping them in the default path - that just makes re-installation and upgrade more complex.

      A word of advise - read the log. That is what it is for. It shows how teh compiler and linker are invoked. Every option you set in a dialog is reflected in the log - that's why we ask for it, but while we can read an interpret it, so could you.

      Clifford

       
    • cpns

      cpns - 2008-05-05

      You say that you need glut.h, but your code has compiled so you obviously don't!

      What you are seeing are linker errors not compiler errors. The symbols it is complaining about are OpenGL symbols not GLUT symbols. Header files are not libraries, they merely declare symbols defined in libraries or object code. The linker command line in your log shows that you have not linked the OpenGL library.

      You need to add -lopengl32 to the linker options.

      Glut is a separate toolkit for use with OpenGL. It may make it easier to use, but in your example you are not using it. Of course that may not be true of your full code. OpenGL is provided with Dev-C++, but Glut is a separate download.

      To use any library (other than the default standard libraries), you must:

      1) Actually have the library and it header file (do they exist on your hard drive?)
      2) Tell the compiler where the header is, either:
      ----a) directly in the #include directive
      ----b) via an include search path defined in the project options (causing a -I<path> switch to be passed to the compiler)
      3) Tell the linker where to find the library, either:
      ----a) by specifying the complete path and file name to the linker
      ----b) adding a library search path to the project options (causing a -L<path> switch to be passed to the linker)and specifying the library via a -l<lib> switch.

      More specifically if you check out the "PLEASE READ BEFORE POSTING A QUESTION" thread, you will find specific information about obtaining and using the OpenGL/Glut libraries.

      To understand compilation, linking, and libraries see: http://sourceforge.net/forum/message.php?msg_id=2670009

      Clifford

       
      • Jarvis Loh

        Jarvis Loh - 2008-05-06

        Thank you for ur prompt help!!

        I understand ur point on not having to use GLUT for the included program.

        I hav typed "-lopengl32" under Tools|Compiler Options|Add these commands to the linker command line. Am I doing the correct thing, in order to link the OpenGL library?

        It is stated in ur reply that

        "Tell the linker where to find the library, either:
        ----a) by specifying the complete path and file name to the linker
        ----b) adding a library search path to the project options (causing a -L<path> switch to be passed to the linker)and specifying the library via a -l<lib> switch."

        I dun quite get what u mean. Is it possible for you to put it in another way?

        Another issue.. In my actual program, which utilises GLUT, I hav downloaded the 3 files (glut.h into C:\Program Files\Microsoft Visual Studio\VC98\Include\GL , glut32.lib into C:\Program Files\Microsoft Visual Studio\VC98\Lib , and glut32.gll into C:\WINDOWS\system32). But when I compile and run, i get the following:

        Compiler: Default compiler
        Executing g++.exe...
        g++.exe "H:\PhD\Research\TESTING2.cpp" -o "H:\PhD\Research\TESTING2.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -lopengl32
        In file included from H:\PhD\Research\TESTING2.cpp:2:
        C:/Dev-Cpp/include/GL/glut.h:44: error: redeclaration of C++ built-in type `short'

        Execution terminated

        Are the locations I hav copied the 3 files correct? Thanks in advance!

        Jarvis

         
        • Wayne Keen

          Wayne Keen - 2008-05-06

          In the thread titled "Please Read Before Posting a Question", there is a section on getting started with Glut. It tells you what to get, where to get it, and where to put it, and how to link. Step by step.

          Note also that libraries for Visual C++ are in general not portable to GCC, the compiler that Dev-C++ uses.

          Wayne

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.