Author Topic: Having a hard time running OpenGL samples with codeblocks.  (Read 10127 times)

Offline indigo0086

  • Almost regular
  • **
  • Posts: 150
Having a hard time running OpenGL samples with codeblocks.
« on: February 23, 2007, 02:16:16 pm »
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>
.
.
.


Offline wxLearner

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #1 on: February 23, 2007, 02:42:49 pm »
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: [Select]
#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>

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

Offline indigo0086

  • Almost regular
  • **
  • Posts: 150
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #2 on: February 23, 2007, 02:46:56 pm »
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

Also, how do I build freeglut for mingw?
« Last Edit: February 23, 2007, 03:01:01 pm by indigo0086 »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9592
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #3 on: February 23, 2007, 04:32:08 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
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.
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

Offline wxLearner

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #4 on: February 23, 2007, 04:36:58 pm »
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]

Offline indigo0086

  • Almost regular
  • **
  • Posts: 150
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #5 on: February 23, 2007, 05:04:49 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
You *need* the GLUT library and headers if you want to compile 3GLUT 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.

ok, here's what I did. 
1) downloaded glut, put glut32.lib in the lib folder of mingw, put glut.h in include/gl of mingw.
2)Created a new project with the opengl template.
3)went to the build options (the universal, not release/debug specific) as show in attachment 1
4) added glut32 to the linker
received the following errors
Code: [Select]
obj\Release\Simple.o:Simple.cpp:(.text+0x17):: undefined reference to `[email protected]'
obj\Release\Simple.o:Simple.cpp:(.text+0x8f):: undefined reference to `[email protected]'
obj\Release\Simple.o:Simple.cpp:(.text+0xe6):: undefined reference to `[email protected]'
:: === Build finished: 3 errors, 0 warnings ===
5) I changed the linker lib to glut32.lib but received
Code: [Select]
ld.exe:: cannot find -lglut32.lib
:: === Build finished: 1 errors, 0 warnings ===


[attachment deleted by admin]

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #6 on: February 23, 2007, 05:11:12 pm »
1) downloaded glut, put glut32.lib in the lib folder of mingw, put glut.h in include/gl of mingw.
2)Created a new project with the opengl template.
3)went to the build options (the universal, not release/debug specific) as show in attachment 1
4) added glut32 to the linker
received the following errors
Code: [Select]
obj\Release\Simple.o:Simple.cpp:(.text+0x17):: undefined reference to `[email protected]'
obj\Release\Simple.o:Simple.cpp:(.text+0x8f):: undefined reference to `[email protected]'
obj\Release\Simple.o:Simple.cpp:(.text+0xe6):: undefined reference to `[email protected]'
:: === Build finished: 3 errors, 0 warnings ===

You can't use glut32.lib (most probably VC compiled) with MinGW. You need library compiled with gcc and with *.a extension. :)
Be a part of the solution, not a part of the problem.

Offline indigo0086

  • Almost regular
  • **
  • Posts: 150
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #7 on: February 23, 2007, 05:13:32 pm »
 :x

Things like that are great to know before you spend all morning figuring out what to do.

Also, dev-pack freezes on me whenever I try to use it.

Offline wxLearner

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #8 on: February 23, 2007, 05:21:39 pm »
If the MinGW linker says -lglut32.lib, it looks for a file called libglut32.lib.a.
You can try to rename your glut32.lib to libglut32.lib.a, or specify a path in the libraries list, but I don't know, if linking with .lib files will work. MinGW supports linking directly to a dll, but for this case you also have to specify a path in the libraries list. It can be a relative path, but if the library is in the same directory you have to explicitely write .\mylib.dll with the preceding .\ (choosing it with the Code::Blocks file browser omits the necessary .\ and makes the linker think, you want to link libmylib.dll.a instead of mylib.dll)

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #9 on: February 23, 2007, 05:28:24 pm »
There is an easy solution. A *.devpak file is basically a *.tar.bz2 file. Rename the devpak file to a *.tar.bz2 file and then extract it using any De-compressor, e.g., 7-zip.

You'll get all the contents easily. :)
Be a part of the solution, not a part of the problem.

Offline indigo0086

  • Almost regular
  • **
  • Posts: 150
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #10 on: February 23, 2007, 06:03:23 pm »
Thanks so much wxLearner for the cbp file, that worked, I can compile the projects with ease now  :D

I tried first by importing the workspace files and compiling it but it didn't work out so well.  I guess I need to get more accustomed to custom building things.

nihilocrat

  • Guest
Re: Having a hard time running OpenGL samples with codeblocks.
« Reply #11 on: February 26, 2007, 04:09:24 am »
I'm having this exact same issue and compiled freeglut myself, but the linker is still complaining about not being able to access all the gl-related fucntions although it can get to the glut ones. What am I missing?