2

I'm wanting to get into and learn OpenGL in C++ and am using Code::Blocks. I was able to get freeglut to work, along with several online examples (as well as the example that ships with CB). However, when I try to include GLEW for some tutorials I'm following, I get the following compiler errors:

obj\Debug\main.o||In function `RenderSceneCB':|
C:\C Programs\OpenGL Test\main.cpp|12|undefined reference to `_imp____glewEnableVertexAttribArray'|
C:\C Programs\OpenGL Test\main.cpp|13|undefined reference to `_imp____glewBindBuffer'|
C:\C Programs\OpenGL Test\main.cpp|14|undefined reference to `_imp____glewVertexAttribPointer'|
C:\C Programs\OpenGL Test\main.cpp|18|undefined reference to `_imp____glewDisableVertexAttribArray'|
obj\Debug\main.o||In function `CreateVertexBuffer':|
C:\C Programs\OpenGL Test\main.cpp|34|undefined reference to `_imp____glewGenBuffers'|
C:\C Programs\OpenGL Test\main.cpp|35|undefined reference to `_imp____glewBindBuffer'|
C:\C Programs\OpenGL Test\main.cpp|36|undefined reference to `_imp____glewBufferData'|
||=== Build finished: 7 errors, 0 warnings (0 minutes, 0 seconds) ===|

No matter what I do, what suggestions I try, what other files I try to link, I keep getting these same errors. I had someone else try the code and they said it worked just fine but didn't have any ideas as to what's wrong with my GLEW setup.

Anyone with any ideas, throw them my way.

I'm using Windows 7, Code::Blocks 12.11, and downloaded Ming32 binaries for GLEW 1.9.0.

My linker setting is set up in this order:

glew32 freeglut opengl32 glu32 winmm gdi32

genpfault
  • 51,148
  • 11
  • 85
  • 139
Justin Lloyd
  • 123
  • 3
  • 11
  • Look at [this question](http://stackoverflow.com/questions/11423700/undefined-reference-to-imp-glewenablevertexattribarray). You will most likely find you solution there. – Anickyan Jun 04 '13 at 17:43
  • possible duplicate of [How to use GLEW with MinGW](http://stackoverflow.com/questions/8870793/how-to-use-glew-with-mingw) – Nicol Bolas Jun 04 '13 at 17:48
  • I'm not sure how either of those answer it. Anickyan, they said they solved their problem by getting GLEW for Mingw32, which is what I stated I already have. As for "How to use GLEW with MinGW" thread, I'm not exactly sure how that is a duplicate, or how it should solve my problem. – Justin Lloyd Jun 04 '13 at 19:05

2 Answers2

3

You have problem in linker setting. You have to link

glew32s.lib

Not only glew32.lib you must link glew32s.lib also .Be sure that it must be at the top of the list of linker.

While writting code don't forget to define

#define GLEW_STATIC

At the top of source file.

Dinesh Subedi
  • 2,603
  • 1
  • 26
  • 36
  • 2
    Dinesh, thank you. That did it! I had tried "glew32s" before but didn't have it at the TOP of the list. When I moved it to the very top of the linker list, the program compiled and worked. Thank you so much, I appreciate it. – Justin Lloyd Jun 05 '13 at 14:45
1

I was struggling getting a GLEW example to work yesterday from https://open.gl/introduction I am working my way through those tutorials and find setting up the environment is always the hardest part. I also use Code:Blocks w/ MinGW and wanted to get into OpenGL. Below you will find a quick summary for building GLEW and SFML yourself and also how to setup a project that uses both...

What after many frustrations worked for me was to download "glew-1.13.0.zip" (the Source ZIP, I had to build GLEW myself) Copy zip file content to C:\ (this path should now work: C:\glew-1.13.0\build\cmake)

You will have to buld GLEW for Code:Blocks w/ MinGW

I got myself CMake (google it)

Copy zip file content to C:\ (C:\CMake3.2.0\bin) and run cmake-gui.exe

In CMake find:

Where is the source code: C:\glew-1.13.0\build\cmake

Where to build the binaries: C:\glew-1.13.0\ownbuild

Click Configure (Pick your compiler in my case "CodeBlocks - MinGW Makefiles") Click Generate (leave the settings alone, just press the button)

Now open C:\glew-1.13.0\ownbuild\glew.cbp in Code:Blocks and build all (shortcut is Ctrl+F9 in CodeBlocks :D )

After the build was a success your GLEW is built and ready for your environment

///////// START - SFML SIDE TRIP Since i am a fan of SFML and the abvoe mentioend tutorial supports it you might want to build and use sfml also

sfml 2-3-2 (google it)

  1. instal oal (oalinst.exe) from openal.software.informer.com/3.0/
  2. In CMake:

Where is the source code: C:/SFML-2.3.2 Where to build the binaries: C:/SFML-2.3.2/build

check SFML_BUILD_EXAMPLES

3. codeblocks: -build "all"

//////// END - SFML SIDE TRIP


Now you want to use GLEW

Create a new console application in code:blocks (I called it "GLEW_sample")

right click on that and choose build options

Now link in CB as follows:

LINKER SETTINGS: (I don't like to keep relative paths) *add all the SFML libs as usual C:\SFML-2.3.2\build\lib\ *add OPENGL.dll from system32 folder C:\Windows\System32\opengl32.dll *add GLEW libs C:\glew-1.13.0\ownbuild\lib\

SEARCH DIRECTORIES: COMPILER: C:\SFML-2.3.2\include C:\glew-1.13.0\include LINKER: C:\SFML-2.3.2\build\lib C:\glew-1.13.0\ownbuild\bin

This is the source code from the above mentioned tutorial https://open.gl/content/code/c2_color_triangle.txt just replace the code in your console application with it and you are good to go.

Now you have built GLEW and SFML w/ Cmake and created a project with working source code. Compile it and enjoy

SabsZor
  • 11
  • 1