[Gc] Experiences/Issues on Windows with Visual Studio/C++

Martin Wartens martin.wartens at mymail.ch
Sun Apr 2 15:48:22 PDT 2006


Hello,
I am curious if somebody is using the gc on Windows (XP) with VC7.1 or VC8.0. I 
had some success building the gc as a static library. For the Release 
configuration I use the additional gc flags
SILENT
GC_BUILD
ALL_INTERIOR_POINTERS
__STDC__
GC_NOT_DLL
REDIRECT_MALLOC=GC_malloc

And for the Debug configuration:
ALL_INTERIOR_POINTERS
__STDC__
GC_NOT_DLL
REDIRECT_MALLOC=GC_malloc

When linking the gc library in debug mode with "REDIRECT_MALLOC=GC_malloc" 
switched on, the linker complains "LNK2005 _calloc, _malloc... already 
defined". The solution is to set 
"Linker->Input->Additional Dependencies":    
"gc.lib ...other libs in the middle... LIBCMTD.lib"
"Ignore specific library":
"LIBCMTD.lib"
"Command Line->Additional Options:"
"/FORCE:MULTIPLE"  
This forces the linker to take the definitions of malloc etc. from the gc.lib. 
It is not a nice solution. (LIBCMTD.lib is the static multi-threaded debug-C-
library.)
Another patch is necessary to make this work. In malloc.c, line 434, it must 
be "defined(MSWIN32)".

To my surprise the definitions of the global "new" operators in gc_cpp.cc are 
not affected by the REDIRECT_MALLOC malloc flag. So I edited that file to 
replace GC_MALLOC_UNCOLLECTABLE by GC_MALLOC.

I tried to add the "GC_THREADS" flag when building the gc, since I am using the 
multi-threaded C-library (which is the only option in VC8.0). But then the 
program crashes during the init phase, when calling "FASTLOCK();" in malloc.c, 
line 316. My program doesn't use threads right now, but I get some spurious 
errors during calls to C-library functions. I suspect they could be caused by 
building the gc without "GC_THREADS".

I made short try to build and use a .dll-version, but I wasn't succesful. There 
was a crash in the init phase. Maybe someone can add something to my 
experiences?

Thanks, Martin



More information about the Gc mailing list