Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My game project is split up into three parts:

  1. Core (lib)
  2. Editor (exe)
  3. Game (exe)

I'm using OpenGL in both my Core and Game parts, but as soon as I try to call an OpenGL function in my Core library the application crashes. I assume this is because the static library is not being linked with OpenGL. The build process goes like this:

# core library
g++  -c  ... -std=c++0x -g  -o ... -I. -I. 
ar rcus libCore.a ...

# game exe
g++ -o Game ... -L. -L../Core/Debug/   -lCore -lglew32 -lglfw -lopengl32

Where ... stands for the various files. How can I link OpenGL with my static library?

share|improve this question
1  
Why can't you just link opengl to both of the executables? –  Jari Komppa Jan 20 '13 at 7:57
    
Really, right now, the editor is not being used. I was just showing it to explain the need for a common library. OpenGL is linked to my executable, and works fine with the executable code. The OpenGL code inside of the core library causes a crash. –  Boreal Jan 20 '13 at 8:05
3  
"I assume this is because the static library is not being linked with OpenGL." Static libraries, in general, do not get linked to other libraries. If a static library requires some dependency in another static library, then any executable/DLL that uses the static library must also link to that dependency. –  Nicol Bolas Jan 20 '13 at 8:30
    
Okay, thanks. I didn't know that! –  Boreal Jan 20 '13 at 15:27

1 Answer 1

up vote 4 down vote accepted

Were you calling glewInit in your main game before core calls any GL functions? If not all the gl function pointers will be null and destined to seg fault. Is Glew built as a static library as well, or as a DLL? If it is built as a static library, is the GLEW_STATIC macro defined when you include it in you core lib? Conversely, if GLEW is built as a DLL, make sure the GLEW_BUILD macro is NOT defined when you include it in your core lib. If nothing is working, make sure you check you can call GL functions from inside you main executable code using GLEW, (and turn off all core library function calls).

share|improve this answer
    
Oh, wow, I'm an idiot. You were perfectly right about the glewInit() call. I created the window just fine in my executable code, but omitted glewInit(), so it appeared that the code in the library was broken due to a linking error. Thanks! –  Boreal Jan 20 '13 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.