0

I'm trying to create a static shader library with OpenGL. I want it to be as portable as possible (Windows Linus Android ...). For this propose i made a header what includes gl and glext: OpenGL.hpp

...
#define GL_GLEXT_PROTOTYPES
#if defined(OS_WINDOWS)

    #ifdef _MSC_VER
        #include <windows.h>
    #endif

    #include <GL/gl.h>
    #include <GL/glext.h>

#elif defined(OS_LINUX)

    #include <GL/gl.h>
    #include <GL/glext.h>
...

And Shader.hpp

...
class Shader
{
    unsigned int m_id;
public:
    Shader();
    ...
};
...

And Shader.cpp

...
#include <Shader.hpp>
#include <OpenGL.hpp>
Shader::Shader()
{
    m_id = glCreateProgram();
    ...
}
...

Then complied Shader.cpp to Shader.o and with ar created libShader.a. After that on android i can compile like that:

g++ -I ./include -c main.cpp -o main.o
g++ -L ./lib -o main main.o -lShader -lSDL2 -lGLESv1_CM -lGLESv2

And it runs flawless. But on windows when i link

g++ -L ./lib -o main.exe main.o -lShader -lSDL2 -lglew32 -lopengl32 -lglu32

G++ gives lib\libShader.a(Shader.o):Shader.cpp undefined reference to glCreateProgram@8 error. On windows main.cpp looks like this:

#include <GL/glew.h>
#include <Shader.hpp>
...
int main()
{
    Shader shader1;
    ...
    GLuint test_id_for_main = glCreateProgram();
    ...
}
...

The wierd thing is test_id_for_main works (if i comment out the Shader-s) without link error. What did i do incorrectly on windows?

Frontier
  • 61
  • 8
  • Are you linking GLEW statically? [Try adding `-DGLEW_STATIC`](http://stackoverflow.com/questions/13384510/glew-linker-errors-undefined-reference-to-glewbindvertexarray). – Cornstalks Feb 15 '14 at 21:19
  • As i can use any glew functionality in main.cpp i don't think that would the problem. – Frontier Feb 15 '14 at 21:24
  • Tried it and still getting the same errors – Frontier Feb 15 '14 at 21:24
  • Also be sure to link to `glew32s` (the `s` at the end is for "static"). – Cornstalks Feb 15 '14 at 21:25
  • Done, still not working. – Frontier Feb 15 '14 at 21:30
  • Are you compiling `main.exe` as 32-bit (rather than 64-bit)? – Cornstalks Feb 15 '14 at 21:31
  • As 32-bit (i have WinXP). – Frontier Feb 15 '14 at 21:35
  • I really don't -get it. You only include GL.h and glext.h, and on Windows, you use glew, but on Linux, you don't (but use GLES instead, where those headers are wrong)? How does your extension handling actually work? And how do you switch between ES and desktop GL? – derhass Feb 16 '14 at 12:11
  • Not linux but android so GLES is valid. I switch between them by using different main.cpp. – Frontier Feb 16 '14 at 12:22
  • You cannot do it that way. When yopu compile your static library, you will have to use GLEW on windows, with the GLEW includes, since these declare the function pointers for all the GL functions. Just using GLEW in the main.o object file will not going to help you there. – derhass Feb 16 '14 at 12:45

1 Answers1

0

I ended up creating my own OpenGL headers and loading the functions with wgl/glx/dlopen

Frontier
  • 61
  • 8