# Unresolved External Symbol

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

## 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 on other sites
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 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 on other sites
Look into "name mangling" and "calling conventions." That should point you towards answers to your question :-)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 17
• 25
• 13
• 20