Oh god. This topic has blown up a bit. Anyways @mcc as for the glX error. No I am not actually getting that error, it was a different error. I just guessed at it because I had that FAQ handy and my misreading was what caused me to decide to just throw the
GLee.c and
GLee.h files into my project.
However I am still getting the
sprintf_s error if I compile anything that uses the GLee library functions,
GLeeInit() in particular. I am working on Windows. I just updated all my software. So I'm running the latest MingW and SDL and Code::Blocks. So that is not the issue. I'm not including windows.h but GLee includes it after checking that I'm running on windows. However the
sprintf_s appears to be part of Microsofts C definition, and not a standard ANSI C command. So I assume I'm just not linking to something that I should be.
There is some concern in my mind for remaining fairly easily cross-platform if not immediately so. So I would rather not require anyone to download MSVC runtime libraries or anything like that if possible.
[EDIT:]
Okay, So here are some the relevent warnings and errors, this is if I link it with the GLee.lib instead of including the source in my project. If I include the source, I don't get the warnings, but I still get the error about an undefined reference to 'sprintf_s'
||Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized|
g:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.6.2\..\..\..\GLee.lib(.\Release\GLee.obj):(.text[___GLeeGetExtStrPlat]+0x29)||undefined reference to `_imp__wglGetCurrentDC@0'|
g:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.6.2\..\..\..\GLee.lib(.\Release\GLee.obj):(.text[___GLeeGetExtensions]+0xd9)||undefined reference to `sprintf_s'|
||=== Build finished: 2 errors, 25 warnings (0 minutes, 13 seconds) ===|
These are my linker commands: -lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_ttf -lSDL_mixer -lglu32 -lopengl32 -lGLee
Reading a bit about
sprintf_s here, it appears that it is merely a "safer" Microsoft created version of the standard
sprintf function. So would it be reasonable for me to just modify GLee to use
sprintf? Or should I be doing something else. Microsoft just says to include
stdio.h, but GLee already includes it, and the function is not defined in the GCC distributed version of the header.
Hmm.. from
looking about, I should apparently just replace the offending line with
snprintf and it will still have a "safer" functionality than simply using
sprintf. Meaning that it will prevent buffer overflows if the string is too large or improperly formatted. However, as pointed out
here, it doesn't produce the same string truncating functionality as the Microsoft version, and merely terminates the program if a overflow occurs.
So, I guess I will just try replacing it with
snprintf and see if that fixes the error.
The relevant function in
GLee.c is reproduced below:
GLboolean __GLeeGetExtensions(ExtensionList* extList)
{
const char * platExtStr;
const char * glExtStr;
char * extStr;
char * p;
int totalExtStrLen = 0;
int addASpace;
/* read the platform specific extension string */
platExtStr=__GLeeGetExtStrPlat();
if (!platExtStr) platExtStr="";
else totalExtStrLen = strlen(platExtStr);
glExtStr=(const char *)glGetString(GL_EXTENSIONS);
if (glExtStr==0)
{
__GLeeWriteError("glGetString(GL_EXTENSIONS) failed.");
return GL_FALSE;
}
/* If the last character of platExtStr is not a space, we need to add one when we concatenate the extension strings*/
addASpace = 0;
if ( totalExtStrLen )
{
if ( platExtStr[ totalExtStrLen-1 ] != ' ')
{
addASpace = 1;
totalExtStrLen++;
}
}
/* allocate the extension string */
totalExtStrLen += strlen(glExtStr);
extStr=(char *)malloc( totalExtStrLen+1 ); /* allow for a null terminator */
/* concatenate the two extension strings */
sprintf_s(extStr,totalExtStrLen+1,addASpace?"%s %s":"%s%s",platExtStr,glExtStr);
/* extract the extensions */
for (p = extStr + totalExtStrLen; p > extStr; --p) {
if (*p == ' ') {
__GLeeExtList_add(extList,p+1);
*p = 0;
}
}
__GLeeExtList_add(extList,extStr);
free((void *)extStr);
return GL_TRUE;
}