I discovered that in MS VS 2010, it is sufficient to:
1) compile a static .lib with overridden functions (#define WIN32_OVERRIDE_ALLOCATORS in config.h). Make sure that 'C++ | Code generation' is set to MT, not MD (not multi-threaded DLL)
2) in your application: set 'C++ | Code generation' to /MT (not /MD!), then put the compiled .lib at the beginning of library list at 'Linker | Input' page.
(Sometimes setting /MT instead of /MD is not perceived by MS VS. You can easily check if it worked: preprocessor symbol '_DLL' must not be defined.)
There is no need to edit default libraries or even to ignore them.
The only patch I had to make is in tcmalloc itself: under Windows, 'getenv' method calls 'malloc' which leads to a deadlock upon TCMalloc initialization. So just don't call 'getenv' in common.cc:
@@ -49,7 +49,12 @@
static inline void InitTCMallocTransferNumObjects()
{
if (UNLIKELY(FLAGS_tcmalloc_transfer_num_objects == 0)) {
+// getenv on MSVC calls malloc which leads to deadlock or stack overflow when linking tcmalloc statically -- V.Makhnychev
+#if !defined(_WIN32) || !defined(WIN32_OVERRIDE_ALLOCATORS)
const char *envval = getenv("TCMALLOC_TRANSFER_NUM_OBJ");
+#else
+ const char *envval = NULL;
+#endif
FLAGS_tcmalloc_transfer_num_objects = !envval ? kDefaultTransferNumObjecs :
strtol(envval, NULL, 10);
}
/FORCE:MULTIPLE