2
\$\begingroup\$

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?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Why can't you just link opengl to both of the executables? \$\endgroup\$ Commented Jan 20, 2013 at 7:57
  • \$\begingroup\$ 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. \$\endgroup\$
    – jmegaffin
    Commented Jan 20, 2013 at 8:05
  • 3
    \$\begingroup\$ "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. \$\endgroup\$ Commented Jan 20, 2013 at 8:30

1 Answer 1

4
\$\begingroup\$

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).

\$\endgroup\$
1
  • \$\begingroup\$ 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! \$\endgroup\$
    – jmegaffin
    Commented Jan 20, 2013 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .