Jump to content
  • Advertisement
Sign in to follow this  
exorcist_bob

another simple linker error

This topic is 4463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!