Jump to content
  • Advertisement
Sign in to follow this  
bkt

DLL Problem (Linker)

This topic is 4865 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

I'm returning a pointer to an API that I have housed inside a DLL, and I'm pretty sure (I've done this a few times before) that I have everything coded right. But when I go to compile the program that will call the DLL, I'm getting a linker error about the deconstructor of the API. Here's the code and the error:
  if( !cmdLine.find("noupdate"))
  {
	  #ifdef _WIN32
		// why does windows always have to be different?
		if(HINSTANCE h=LoadLibrary("surveNET.dll"))
	    {
			typedef ISurveAPI* (*EXPORTAPI) ();
			EXPORTAPI pfnExport;

			if( !(pfnExport = (EXPORTAPI) GetProcAddress(h,"ExportAPI")) )
			{
				::MessageBoxA(NULL,"Failed loading surveNET.dll; please check your installation.\nec0",
					"Error",MB_OK|MB_ICONSTOP);
				return -1;
			}

			shared_ptr<ISurveAPI> pSurve = shared_ptr<ISurveAPI> ( pfnExport() );
			::FreeLibrary(h);
		}	
		else
	    {
			::MessageBoxA(NULL,"Failed loading surveNET.dll; please check your installation.\nec1",
				"Error", MB_OK|MB_ICONSTOP);
			return -1;
		}
	  #endif
	  return -1;
  }



main.obj : error LNK2019: unresolved external symbol "public: __thiscall ISurveAPI::~ISurveAPI(void)" (??1ISurveAPI@@QAE@XZ) referenced in function "public: void * __thiscall ISurveAPI::`scalar deleting destructor'(unsigned int)" (??_GISurveAPI@@QAEPAXI@Z)
../../bin/launch.exe : fatal error LNK1120: 1 unresolved externals


I know I'm probably missing something blatently stupid. But here's also the header file that is being used for both the DLl complication and the inclusion for the library in the main program.
class ISurveAPI
{
	public:
		// constructor/destructor
		ISurveAPI(void);
		ISurveAPI(const ISurveAPI&);
		~ISurveAPI(void);
};



Share this post


Link to post
Share on other sites
Advertisement
change the line of the destructor into this:
~ISurveAPI(void) {};
before, you only had the declaration of the destructor. Now it also has the body (which does nothing).

Share this post


Link to post
Share on other sites
But maybe the linker doesn't know that it is in the dll. Maybe you should use GetProcAddress on that function too and somehow tell the linker to use it.

Share this post


Link to post
Share on other sites
But that would besides the whole point of exporting a class from a DLL. I should only have to do it once, and once only. Its only calling it because the shared_ptr falls out of scope, and the constructor is called within the DLL itself.

Share this post


Link to post
Share on other sites
The linker needs the definition for that class, or more specifically the desctr. You need to
a) include the class definition in your main app/calling code
b) statically link to the dll

You may have never run into this before as usually you just call getprocaddress on a method that uses data taht the linker knows about.

If you don't let the linker know where teh definition is then how do you expect it to link:)

Cheers
Chris

Share this post


Link to post
Share on other sites
I want to be able to use the DLL as a library through more than one code, why should I need to statically link the library each and every time I compile? There isn't a way to just export the class instance from the DLL?

Share this post


Link to post
Share on other sites
there is but the linker needs the definition so it needs to be there at link time. hencethe need to have the dll's linker lib. that doesn't mean you can't useit as a dll, you just need to includeits linking lib.

cheers
chris

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!