Jump to content
  • Advertisement
Sign in to follow this  
jamesleighe

Unresolved External Symbol

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

dllmain.cpp

DLLEXPORT void* GetApi ()
{
extern IPhysicsSystem* _g_PhysicsSystemInstance;
return (void*)_g_PhysicsSystemInstance;
}


globals.cpp

class IPhysicsSystem;


// system global
IPhysicsSystem* _g_PhysicsSystemInstance = NULL;


It would seem that somehow it's not seeing the definition of the global. But if I redefine it in dllmain.cpp it complains of multiply defined symbols!

I can fix the problem by moving the definition out of globals.cpp and into dllmain.cpp where it is first used, but what is going on here?

Thanks as usual!

Share this post


Link to post
Share on other sites
Advertisement
Correct me if I am wrong...

Can't you declare your variable (IPhysicsSystem* _g_PhysicsSystemInstance) globally? Isn't that what you really want:
dllmain.cpp

extern IPhysicsSystem* _g_PhysicsSystemInstance;

DLLEXPORT void* GetApi ()
{

return (void*)_g_PhysicsSystemInstance;
}


globals.cpp

IPhysicsSystem* _g_PhysicsSystemInstance = NULL;


From what I know, extern allows you to declare a variable inside the global scope of a source-file, and use it (when properly initialized on another file) by another file.
What happens when you declare it inside the scope of a function?

Sorry if I am the one making questions here =D

Share this post


Link to post
Share on other sites
Whelp, moving the extern like you said fixes the issue!

But that's a bit odd since I use externs inside function scope all over the place with no issue (yet!).

It has something to do with the fact that I'm using "extern "C" __declspec (dllexport)" to declare the function because if I remove it it also works fine.
How is a function declared for export from a dll different from a normal function?

Share this post


Link to post
Share on other sites
Look into "name mangling" and "calling conventions." That should point you towards answers to your question :-)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!