Skip to main content
GameDev.net gamedev.net
🔒 Locked

another simple linker error

Started by exorcist_bob Apr 29, 2006 at 8:20 AM 0 replies 950+ views
Original Post
exorcist_bob
exorcist_bob
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
mikeman
mikeman
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.