1

I'm trying to compile the SDL libraries with Visual C++ (2010), and with Visual Leak Detector as to find a memory leak in another program that calls SDL.

The problem is that vld.h is a C++ library, and SDL.c is a C program. Accordingly, when I #include , the source doesn't compile as VLD seems to use a C++ specific constructs:

typedef int (__cdecl * VLD_REPORT_HOOK)(int reportType, wchar_t *message, int *returnValue);

__declspec(dllimport) int VLDSetReportHook(int mode,  VLD_REPORT_HOOK pfnNewHook);

I've attempted compiling SDL.c as a C++ program, but I get a plethora of errors.

Is there any way I can include VLD in SDL?

lochok
  • 363
  • 1
  • 4
  • 20
  • What is the C++ specific construct? I don't see anything C++-specific in that code. – Dr. Snoopy Jan 09 '12 at 00:19
  • I'm not sure (I've only ever done C++, and I'm not great at it). I assumed that was the code. It compiles in a C++ program, but when in SDL.C, it creates the following errors: 1>c:\program files (x86)\visual leak detector\include\vld_def.h(44): error C2143: syntax error : missing ')' before '*' 1>c:\program files (x86)\visual leak detector\include\vld_def.h(44): error C2081: 'wchar_t' : name in formal parameter list illegal 1>c:\program files (x86)\visual leak detector\include\vld_def.h(44): error C2143: syntax error : missing '{' before '*' – lochok Jan 09 '12 at 00:22
  • 1>c:\program files (x86)\visual leak detector\include\vld_def.h(44): error C2059: syntax error : 'type' 1>c:\program files (x86)\visual leak detector\include\vld_def.h(44): error C2059: syntax error : ')' – lochok Jan 09 '12 at 00:22
  • The only other place where it fails was just edited into the question. – lochok Jan 09 '12 at 00:25
  • 1
    Looks like it's complaining about wchar_t, you should #include – Dr. Snoopy Jan 09 '12 at 01:34

1 Answers1

3

(with thanks to @Matias Valdenegro)

The problem was the wchar_t. To be able to recompile SDL (and I assume other C source files) to include VLD, add

#include <wchar.h>

to both vld.h and vld_def.h. SDL will then happily compile, and can be used with an SDL program to detect memory leaks stemming from Surfaces and the like.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
lochok
  • 363
  • 1
  • 4
  • 20