User forums > Using Code::Blocks

Having a hard time running OpenGL samples with codeblocks.

(1/3) > >>

indigo0086:
I recently bought the book, "Beginning OpenGL game programming" and it's a nice book so far, but when I try to run the samples I get a mess of errors.  I am using the mingw compiler and it finds the gl/glut.h file but when I try to compile it I get these errors in from the glut.h header


--- Quote ---Z:\mingw\include\gl\glut.h:50: error: redeclaration of C++ built-in type `short'
Z:\mingw\include\gl\glut.h:58: warning: ignoring #pragma comment
Z:\mingw\include\gl\glut.h:66: warning: ignoring #pragma comment
Z:\mingw\include\gl\glut.h:67: warning: ignoring #pragma comment
Z:\mingw\include\gl\glut.h:68: warning: ignoring #pragma comment
Z:\mingw\include\gl\glut.h:76: warning: ignoring #pragma warning
Z:\mingw\include\gl\glut.h:77: warning: ignoring #pragma warning
Z:\mingw\include\GL\gl.h:1587: error: `WINAPI' does not name a type
<WINAPI REPEADTED over and over>
.
.
.

--- End quote ---

wxLearner:
That is not a Code::Blocks problem. It just uses your files and compiler and shows the compiler messages.
Concerning glut, I would recommend using freeglut. WINAPI should be defined, if windows.h is included; freeglut does it the in the following way:
--- Code: ---#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)

/* #pragma may not be supported by some compilers.
 * Discussion by FreeGLUT developers suggests that
 * Visual C++ specific code involving pragmas may
 * need to move to a separate header.  24th Dec 2003
 */

#   define WIN32_LEAN_AND_MEAN
#   define NO_MIN_MAX
#    include <windows.h>
--- End code ---

Probably your version of glut doesn't check for MinGW.

indigo0086:
OK I added windows.h and #define GLUT_NO_LIB_PRAGMA #define GLUT_NO_WARNING_DISABLE to get rid of most of the errors, but now I get "ld.exe: cannot find -lglut32.lib"

here is the log full command line mode.


--- Quote ---mingw32-g++.exe -Wall -g  -IZ:\mingw\include -IZ:\MinGW\include  -c "Z:\Cpp\OpenGL Examples\Simple\Simple.cpp" -o obj\Debug\Simple.o
mingw32-g++.exe -LZ:\mingw\lib -LZ:\MinGW\lib  -o bin\Debug\Simple.exe obj\Debug\Simple.o    -lopengl32 -lglu32 -lgdi32 -lglut32.lib -llglut32.lib
Z:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lglut32.lib
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
--- End quote ---

Also, how do I build freeglut for mingw?

MortenMacFly:

--- Quote from: indigo0086 on February 23, 2007, 02:46:56 pm ---mingw32-g++.exe -LZ:\mingw\lib -LZ:\MinGW\lib  -o bin\Debug\Simple.exe obj\Debug\Simple.o    -lopengl32 -lglu32 -lgdi32 -lglut32.lib -llglut32.lib
Z:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lglut32.lib

--- End quote ---
You *need* the GLUT library and headers if you want to compile GLUT applications. They are *not* provided with MinGW. Try google and/or download the GLUT DevPack. Then add the path of the GLUT headers to the compiler options and the path to the GLUT libs to the linker options.
The very same applies to freeGLUT. IMHO there is a pre-compiled DevPack available, too. Nothing required to compile yourself here (except your very application), just make your project aware of where to find (free)GLUT stuff.
With regards, Morten.

wxLearner:
To make the linker find your libs in none standard directories, you have to specify the search directories. In Code::Blocks you can do this for a project or a target in the build options of your project or you can set it globally (Settings => Compiler and debugger).
Regrettably you cannot set search directories and libraries for a group of projects (i. e. workspace). Building freeglut is very easy; you can import the VC++ project file. After that you can adjust it a little to also create a static library, so your programs don't need the dll. I've attached a Code::Blocks project that can be used to build the freeglut as static library or dll. Just put the project file into the freeglut-2.4.0 folder and open it with Code::Blocks.

P.S. If you want to link freeglut statically, don't forget to define FREEGLUT_STATIC.

[attachment deleted by admin]

Navigation

[0] Message Index

[#] Next page

Go to full version