views:

405

answers:

3

I am using __declspec(dllimport/export) on a debug version of new as such:

#ifdef _DEBUG
 DECLSPECCORE extern   void* operator new(unsigned int size, const char* file, int line);
 extern void* operator new[](unsigned int size, const char* file, int line);
 extern void operator delete(void* address, const char* file, int line);
 extern void operator delete[](void* address, const char* file, int line);
 extern void Delete(void* address);

#define LUDO_NEW new(__FILE__, __LINE__)
#define LUDO_DELETE delete

#endif

This is causing me to get

error C2375: 'operator new': redefinition; different linkage.

Why is this and how can you fix it? This is the only project that I am compiling right now.

A: 

The C++ runtime itself provides an operator new, which is not marked as DECLSPECCORE -- hence "different linkage", the original was not imported from another module. If you intend to override operator new, it should have the same linkage as before.

ephemient
A: 

Your code is saying that you want C++'s "operator new" to be exported as a function callable from outside the DLL. Assuming that's even possible (probably not): Are you sure that's what you want to do?

Dennis
+1  A: 

If you have two two prototypes of overloading the new operator you must export both. Hopefulyl that is your problem.

UberJumper