[solved] Linking to release/ AND relwithdebinfo/OgreMain.lib

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

[solved] Linking to release/ AND relwithdebinfo/OgreMain.lib

Post by Jabberwocky »

I just noticed a linking oddity in my game, which uses both CEGUI and Ogre.
CEGUI is linking to: C:/space/ogre/build/ogre_src_v1-7-1/lib/release/OgreMain.lib
My game (a separate visual studio project) is linking to: C:/space/ogre/build/ogre_src_v1-7-1/lib/relwithdebinfo/OgreMain.lib
I have copied the relwithdebuginfo/OgreMain.dll to my executable directory, so this matches my game linking, but does not match CEGUI linking.

So, CEGUI is linking to a differently configured OgreMain.lib than I have a .dll available for in my executable directory.
Why have I not noticed this error before, and why does my application work? Are the relwithdebinfo and release versions of a .dll sorta compatible, or is it just a fluke that I haven't crashed?
Last edited by Jabberwocky on Wed Jul 06, 2011 10:26 am, edited 1 time in total.
Image
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Linking to release/ AND relwithdebinfo/OgreMain.lib

Post by xavier »

It works because they are both using the same MSVCRT variant (release).

The "withdebinfo" is simply Release plus "generate PDB data" flags.

As for which DLL functions are actually used at runtime, generally, the way dynamic loaders work, is that symbols are used from the first loaded library that defines them.

BTW, this is how you can override, at runtime and with no recompilation or relinking, exported functions such as malloc and free (which is what, for instance, the tbbmalloc DLL does).
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: Linking to release/ AND relwithdebinfo/OgreMain.lib

Post by Jabberwocky »

Thanks. That's very informative.

I'm still somewhat unclear on how tightly coupled the .dll and the .lib are. For example:

1. Let's say I link MyGame.exe to a OgreMain.lib compiled with full optimization, say /O2 in visual studio. Then I recompile OgreMain with a lesser optimization, say /Od, generating a new OgreMain.lib and OgreMain.dll. Can I just drop the new OgreMain.dll into my game directory and will it work without relinking MyGame.exe?

2. Let's say I link MyGame.exe to OgreMain.lib. Then I make a change to a function inside OgreMain, without changing the API and function signatures, generating a new OgreMain.lib and OgreMain.dll. Can I just drop the new OgreMain.dll into my game directory and will it work without relinking MyGame.exe?
Image
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Linking to release/ AND relwithdebinfo/OgreMain.lib

Post by xavier »

Jabberwocky wrote: 1. Let's say I link MyGame.exe to a OgreMain.lib compiled with full optimization, say /O2 in visual studio. Then I recompile OgreMain with a lesser optimization, say /Od, generating a new OgreMain.lib and OgreMain.dll. Can I just drop the new OgreMain.dll into my game directory and will it work without relinking MyGame.exe?
Since we're talking about OgreMain.dll, we clearly are talking about Windows. On Windows, there no longer is a single-threaded runtime library, and with Ogre you generally are always linking to the DLL runtime (when building an OgreMain.dll). So you are always linking either to the release (MSVCRTxx.DLL) or debug (MSVCRTxxD.DLL). The only flag that matters in this case, and this is set in Project Properties, C++, Code Generation, Runtime LIbrary, is /MD or /MDd (the /MT variants are for the static multithreaded runtimes). This is the only flag that will determine whether you use debug or release. So the short answer to your question above -- yes.

This is why DLLs were invented in the first place -- so you could drop in new (fixed/improved/etc) versions without having to relink every app that uses them.
2. Let's say I link MyGame.exe to OgreMain.lib. Then I make a change to a function inside OgreMain, without changing the API and function signatures, generating a new OgreMain.lib and OgreMain.dll. Can I just drop the new OgreMain.dll into my game directory and will it work without relinking MyGame.exe?
Again yes, for the reason stated above. The API is the same (the signatures have not changed), so everything works fine. This is why you can get updated Windows DLLs and all of your apps still work fine.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: Linking to release/ AND relwithdebinfo/OgreMain.lib

Post by Jabberwocky »

Much appreciated, Xavier.
Image
Post Reply