I am developing static library that takes screenshots, and taking them from OpenGL applications require special handling.
When client application links to my static library it have to add frameworks used by my library, for example to take OpenGL screenshots, even if client app is not using OpenGL it have to link with OpenGLES.framework which is bad. I am trying to check in the library if client have linked with OpenGLES.framework and dynamically enable taking screenshots from OpenGL.
The problem is I get compilation error when I try to use C functions like:
if(&glReadPixels != NULL) {
glReadPixels(0, 0, size.width, size.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
}
As you can see, I can check for method existence, but how do I invoke it to not cause linker error? When I compile client with my library I get this:
Undefined symbols for architecture i386:
"_glReadPixels", referenced from:
+[TakeScreenshotUtil takeOpenGLScreenshotWithContext:layerSize:] in libScr-iOS.a(TakeScreenshotUtil.o)
I am trying to use
__attribute__ ((weak))
but it doesn’t work (doesn’t change anything).
You can open app being executed and check if it links to OpenGL. First, recompile your app with -rdynamic (or whatever equivalent Apple’s GCC understands). Then use the following code to find a function: