views:

172

answers:

4

I have a library opengl.lib which contains wrapper functions to all opengl functions. The functions are declared in their own namespace so that the wrapper functions can be named with the same name as the opengl functions. So inside a wrapper function, opengl function is called with ::gl***();

opengl.h:
namespace OpenGL {
    void glFunction();
}

opengl.cpp:
void OpenGL::glFunction() {
    ::glFunction();
}

Now the problem is that when I use this opengl.lib in my application and include my own "opengl.h", for some reason the real opengl functions get called directly and not my wrapper functions.

I have made sure that I have not included any real opengl.h so this must be some kind of linker issue. How can I resolve it? I have also the real opengl library in library path because otherwise I get linker errors in my opengl.lib as it uses the real opengl functions. So the real opengl library and my opengl.lib gets somehow mixed and linker decides to use the real opengl.lib instead of mine.

I know I can solve this by renaming my wrapper functions to something else but I would like to use the same names.

This question relates to my previous question http://stackoverflow.com/questions/565459/c-wrapper-with-same-name

I am using Visual C++ with optimization disabled.

+2  A: 

Are your wrappers thin enough that they are being inlined?

Ryan Graham
A: 

Is the actual opengl.h named the same thing as your wrapper header file? If it is, probably you are including it without realizing it, since the compiler searches system paths before user defined paths.

Greg Rogers
Nope, this is not the problem
A: 

Looking at the pre-processed cpp file can be really helpful to resolve this kind of problem.

In visual C++, go in the properties of the file including your opengl.h, in Preprocessor enable the "Generate Proprocessed File" option (/P)

This will generate a .i file

total
A: 

You should only need to link with the real opengl lib when you are building your opengl.lib. Make sure that you dont have any references to the real opengl lib in the project(s) that are using your own lib. If you don't have any references to the real lib, there is no way that the real functions can be called. Once that is done, make sure that you are using the correct namespace.

// Call OpenGL::glFunction();
using namespace OpenGL;
glFunction();
Magnus Skog