Sign in to follow this  
exorcist_bob

another simple linker error

Recommended Posts

Hello, I get the following linker error for what seems to be no reason at all. 1>SWPBase.obj : error LNK2001: unresolved external symbol "void __cdecl SkepWorks::Memory::Free(void *,unsigned int)" (?Free@Memory@SkepWorks@@YAXPAXI@Z) It only happens when I uncomment this line:
#pragma once
#include "SWMemory.h"

namespace SkepWorks
{
	class SWPBase
	{
	public:
		SWPBase(void);
	public:
		virtual ~SWPBase(void);

		void *operator new (size_t size) { return Memory::Alloc (size); }
		//void operator delete (void *ptr, size_t size) { Memory::Free (ptr,size); } //this line
		void *operator new[] (size_t size) { return Memory::Alloc (size); }
		void operator delete[] (void *ptr, size_t size) { Memory::Free (ptr,size); }
	};
}

Why is it being so erratic? There are no errors in my operator delete[] function that uses the exact same function. SWMemory.h:
#include "SkepWorks.h"

namespace SkepWorks
{
	namespace Memory
	{
		//more functions
		SkepWorksExport void Free (void *ptr, size_t size);
	};
}

void Free (void *ptr, size_t size)
{
  if (!ptr)
	  return;

  if (freefn)
	  freefn (ptr,size); 
  else 
	  free (ptr);
}

Thanks for any assistance, exorcist_bob

Share this post


Link to post
Share on other sites
If you look closely, you'll see that the definition(implementation) of Free() is outside of the SkepWorks::Memory namespace. So it's natural that the linker doesn't find the function SkepWorks::Memory::Free(), because it simply doesn't exist. The reason that the error rises only on "operator delete" is probably that you don't have a call to "operator delete[]" in your program, and so the compiler optimizes: If there is an unresolved reference inside a member function that is never used anyway, it just doesn't complain(at least that's what my compiler does).

Just put the definition of Free() inside the correct namespace.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this