1

I have a static library in which I'm calling OpenGL extension functions via GLEW. As the project is being built in GCC (NetBeans 7.0), and GLEW's binaries are only shipped in Visual-C flavor, I have built GLEW (1.7.0) as a static library, with GCC. (I would also be interested why this is necessary, as GLEW seems to be pure C, in which ABI and cross-compiler compatibility isn't an issue AFAIK.)

In my static library I define GLEW_STATIC and NO_SDL_GLEXT as project preprocessor directives (-D), then I

#include "GL/glew.h"
#include "SDL/SDL.h"

The static library is then linked against in a (test) application, which also links against the following libraries, in the following order:

my_static_library
mingw32
glew32
opengl32
SDLmain
SDL

This setup gives me two undefined reference errors in my static library:

undefined reference to `_imp____glewGetStringi'
undefined reference to `_imp__glewInit'

Indeed, these are two calls made to GLEW functionality, in the static library. There are however other calls that the linker used to complain about (before -DGLEW_STATIC), yet seem to be ok now.

I wasn't able to improve the situation by swapping the order of linkage to opengl32 and glew32 (some more undef'd refs to wgl... calls). Furthermore, GLEW_STATIC (and NO_SDL_GLEXT) used to be defined in the test application but that has been removed and doesn't seem to matter.

Why do the remaining errors occur and what can I do to get rid of them, i.e. how can I use GLEW in GCC with SDL?

zyndor
  • 1,418
  • 3
  • 20
  • 36
  • 1
    While the calling conventions are about the same, Visual-C links against another runtime standard library, as GCC, which are – unfortunately – incompatible. That's the main reason why you have to recompile with GCC. – datenwolf Nov 14 '11 at 08:46
  • No, mingw32 GCC links to the Microsoft's runtime libraries - `msvcrt.dll`, `kernel32.dll`, etc. It only uses import libraries in `ar(1)` format. – chill Nov 14 '11 at 09:36

1 Answers1

1

You library was built in such a way, as to link to the DLL version of GLEW - _imp____glewGetStringi and _imp__glewInit are import library symbols, i.e. the combination of defines resulted in the following line appearing when compiling;

extern __declspec(dllimport) PFNGLGETSTRINGIPROC __glewGetStringi;

This can happen if you don't define GLEW_STATIC while compiling your library (but you do; double check each object)

or

your version of GLEW has a bug in the headers. In GLEW 1.7.0 it works as expected.

chill
  • 16,470
  • 2
  • 40
  • 44
  • Hi chill, Thank you for your reply. I've got GLEW 1.7.0 (added this to the question) and I define GLEW_STATIC at a project level. How can I have my project link against the static version of GLEW? And could you clarify what you mean by double checking each object? (The binaries?) – zyndor Nov 14 '11 at 14:32
  • @iCE-9, when you get he unresolved external error, the linker should tell you the files, which contain the unresolved reference. Check the project log, to be sure that these files had `-DGLEW_STATIC` on the command line, used to compile them. – chill Nov 14 '11 at 15:01
  • I've already had it added to the project defines, so that it's defined for each source file, and indeed, adding a #define GLEW_STATIC to the file that's triggered the linker error resulted in a "GLEW_STATIC redefined" error. Ironically, it was the objects that needed double-checking: after I got the redefinition error and removed GLEW_STATIC from the source code, it (re)compiled and linked fine... (yes, it'd been rebuilt before) – zyndor Nov 14 '11 at 21:37