Code::Blocks
April 20, 2014, 10:15:09 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: The new Release 13.12 is out! You can download binaries for windows, mac and many major linux distros from  http://www.codeblocks.org/downloads/26 .
 
   Home   Help Search Login Register  :: WebsiteWiki  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: [help needed] problem with setting up C::B for using GLUT  (Read 1776 times)
Riker1990
Guest
« on: April 17, 2009, 07:08:08 pm »

Recently I downloaded Code::Blocks 8.02 and yesterday I've decided to learn something about OpenGL. I got a link to a tutorial from my friend so I just went for it.
First thing I decided to do was to compile the example program from that tutorial and run it .Here's it's code (original comments only in polish, sorry):
Code:
/*
(c) Janusz Ganczarski (Power)
http://www.januszg.hg.pl
JanuszG@enter.net.pl
*/

#include <GL/glut.h>
#include <stdlib.h>

// funkcja generująca scenę 3D

void Display ()
{
    // kolor tła - zawartość bufora koloru
    glClearColor (1.0,1.0,1.0,1.0);

    // czyszczenie bufora koloru
    glClear (GL_COLOR_BUFFER_BIT);

    // kolor kwadratu
    glColor3f (1.0,0.0,0.0);

    // początek definicji wielokąta
    glBegin (GL_POLYGON);

    // kolejne wierzchołki wielokąta
    glVertex3f (0.0, 0.0, 0.0);
    glVertex3f (0.0, 1.0, 0.0);
    glVertex3f (1.0, 1.0, 0.0);
    glVertex3f (1.0, 0.0, 0.0);

    // koniec definicji prymitywu
    glEnd ();

    // skierowanie poleceń do wykonania
    glFlush ();

    // zamiana buforów koloru
    glutSwapBuffers();
}

// zmiana wielkości okna

void Reshape (int width, int height)
{
    // generowanie sceny 3D
    Display ();
}

// stałe do obsługi menu podręcznego

enum
{
    EXIT // wyjście
};

// obsługa menu podręcznego

void Menu (int value)
{
    switch (value)
    {
        // wyjście
        case EXIT:
        exit (0);
    }
}

int main (int argc, char *argv[])
{
    // inicjalizacja biblioteki GLUT
    glutInit (&argc,argv);

    // inicjalizacja bufora ramki
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);

    // rozmiary głównego okna programu
    glutInitWindowSize (400,400);

    // utworzenie głównego okna programu
    glutCreateWindow ("Kwadrat 1");

    // dołączenie funkcji generującej scenę 3D
    glutDisplayFunc (Display);

    // dołączenie funkcji wywoływanej przy zmianie rozmiaru okna
    glutReshapeFunc (Reshape);

    // utworzenie menu podręcznego
    glutCreateMenu (Menu);

    // dodadnie pozycji do menu podręcznego
#ifdef WIN32

    glutAddMenuEntry ("Wyjście",EXIT);
#else

    glutAddMenuEntry ("Wyjscie",EXIT);
#endif

    // określenie przycisku myszki obsługującej menu podręczne
    glutAttachMenu (GLUT_RIGHT_BUTTON);

    // wprowadzenie programu do obsługi pętli komunikatów
    glutMainLoop ();
    return 0;
}
I downloaded GLUT from OpenGL page and extracted both .dll's to windows/system and windows/system32 (wasn't sure where it's supposed to go), extracted .h to MinGW/include/GL and .lib's to MinGW/lib and also Extracted all 5 files to a separate folder. Then I created new GLUT project in C::B, and I was asked about the folder to which GLUT was unpacked - I responded with MinGW's folder. I pasted the example program's source into newly created main.cpp, then I linked both glut.lib and glut32.lib to the project (in project\build options\linker settings) and tried to compile and received an error (and some warnings about ignoring pragma content as well)
Code:
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|43|error: redeclaration of C++ built-in type `short'
in header file in lines:
Code:
#  ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#   define _WCHAR_T_DEFINED
Uncle Google told me that stdio.h should be included before glut.h so I tried that one and got:
Code:
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|48|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|49|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|50|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|51|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|53|warning: ignoring #pragma warning |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|54|warning: ignoring #pragma warning |
obj\Debug\main.o||In function `_Z7Displayv':|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|15|undefined reference to `__imp__glClearColor'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|18|undefined reference to `__imp__glClear'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|21|undefined reference to `__imp__glColor3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|24|undefined reference to `__imp__glBegin'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|27|undefined reference to `__imp__glVertex3f|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|28|undefined reference to `__imp__glVertex3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|29|undefined reference to `__imp__glVertex3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|30|undefined reference to `__imp__glVertex3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|33|undefined reference to `__imp__glEnd'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|36|undefined reference to `__imp__glFlush'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|39|undefined reference to `_glutSwapBuffers'|
obj\Debug\main.o||In function `main':|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|72|undefined reference to `_glutInit'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|75|undefined reference to `_glutInitDisplayMode'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|78|undefined reference to `_glutInitWindowSize'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|81|undefined reference to `_glutCreateWindow'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|84|undefined reference to `_glutDisplayFunc'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|87|undefined reference to `_glutReshapeFunc'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|90|undefined reference to `_glutCreateMenu'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|95|undefined reference to `_glutAddMenuEntry'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|102|undefined reference to `_glutAttachMenu'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|105|undefined reference to `_glutMainLoop|
||=== Build finished: 21 errors, 6 warnings ===|
I created new GLUT project, linked both .lib's and tried to compile the code that is in every new GLUT project by default, included stdlib.h before glut.h and tried to compile. This time I got 50 "undefined reference" errors, more followed but weren't displayed.

If even the default code in an example program doesn't work then I guess it's not compiler/OpenGL issue, I guess I screwed something up (with GLUT). Any idea how to make these two programs work/what have I done wrong?

I described all the things I've done as detailed as possible. I'm using on WinXP sp2.
Logged
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8543



« Reply #1 on: April 17, 2009, 08:18:01 pm »

Any idea how to make these two programs work/what have I done wrong?
In addition to the libs mentioned you'll need to link against the OpenGL32 lib, too. Notice that also the order of the libs´matters as they depend on each other. Why don't you let the wizard create yourself a GLUT project and inspect it's settings?
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
Riker1990
Guest
« Reply #2 on: April 18, 2009, 12:22:02 am »

The only opengl lib I have that was already installed with CB is libopengl32.a. I tried including it but it didn't work. I'll download OpenGL32.lib and try it tomorrow.

When I create a new OpenGL project there are no libraries linked (at least none are mentioned in linker settings), just like in a new GLUT project. I'm thinking of reinstalling CB, maybe that would help, but anyway I'll try it tomorrow.

As for the order of libs linked I'd say OpenGL32.lib must be linked first, is that correct?

Update:

There was no OpenGL32.lib in my C::B installation, so I "borrowed" it from VS. After including everything works as it should.

I still don't get why new OpenGL project (with default source code) doesn't need that library (I can't see it on linker's "linked libraries" list). Well, at least it works now, so thx for help:)
« Last Edit: April 18, 2009, 05:33:20 pm by Riker1990 » Logged
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8543



« Reply #3 on: April 18, 2009, 09:06:10 pm »

I still don't get why new OpenGL project (with default source code) doesn't need that library (I can't see it on linker's "linked libraries" list).
Notice that a project does have (at least one) target. You can setup libraries at 3 places:
1.) The compiler settings (it makes no sense there btw...)
2.) At project level
3.) At target level
I am *sure* that on one of the last two you'll find the libs because you *need* to link against them. You can also enable the full command line log (see my sig) to check the linker command. This will also tell you the right order then.
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
ollydbg
Developer
Lives here!
*****
Offline Offline

Posts: 3880


Interests on OpenCV and Robotics


WWW
« Reply #4 on: April 19, 2009, 10:55:13 am »

See my post about linking to GLUT.

http://forums.codeblocks.org/index.php/topic,10419.msg71718.html#msg71718
Logged

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!