views:

191

answers:

2

How do you construct a library (static lib or a dll/so) so that it isn't sensitive to future updates to the system's C runtime librarires?

At the end of July, Microsoft updated a bunch of libraries, including the C runtime libraries. Our app is written with a mix of MFC/C++/VB and some third party libraries, including some that are closed source.

I've been busy recompiling all of the libraries we have source to, but I am wondering if it is really necessary? What will happen if we link in or load a library built against an earlier version of the C runtime?

When recompiling this stuff, what compiler and linker settings must be the same between the main application and the supporting libraries? I've discovered that the runtime library setting needs to be the same (we use the multi-threaded version /MD and /MDd) but I'm worried about other settings. I've actually pulled all the settings out into Visual Studio property sheets and I'm using the same sheets for all our different projects, but this doesn't work for 3rd party libraries and I'm thinking it is overkill.

I have noticed that the linker will spit out a warning about conflicting libraries, but it suggests to just ignore the default libraries. Is it safe to do so? It seems like a very ugly solution to the problem.

+1  A: 

If you or your third-party components are statically linking against out-of-date C libraries, you are fine; upgrades to those libraries will not affect your program. Of course, you won't benefit from any bug fixes or performance upgrades or what-have-you either. If you do recompile your code to take advantage of your new settings, all runtime switches must be the same. This is always the case, regardless of when or why your libraries are compiled. It is probably safe to ignore the default libraries (I've been doing so for years without difficulty).

Dynamically-linked libraries are another story. If you rely on the target system having a particular version of a given dll, and it has some other incompatible version instead, then you are screwed. The traditional solution to this problem is to bundle all the dlls you need with your executable. Microsoft's new side-by-side assembly thing might also be able to help, but it's always been a little too hard to set up for me to bother with it. You might have better luck.

David Seiler
I thought statically linked libraries were the most sensitive. Is it going to be a problem if, for example, my app and a library have different heap managers?As for the critical switches- any idea where I could find a list of these? I'm thinking settings related to exception handling, structure packing, floating point model, etc... are critical but I would like some documentation on this.Every time there is a bump in the c runtime version on my system, do I need to be calling our library vendors to demand new builds?
criddell
+1  A: 

If you are loading the 3rd party libraries as DLLs, they may depend on different runtime versions than your executable as long as

  • you are not handing over parameters of types, that depend on the runtime libs (like STL types)
  • the 3rd party lib is able to load the version of the runtime, that it has been built with or is statically linked to the runtime

So, you don't have to recompile the DLLs.

If you are statically linking to the libs or if you are handing over types defined in the runtime DLLs, you may get some problems with symbols, that are already imported in your lib, so most likely you will have to recompile it.

Bernd
Hmmm... so only primitives should be passed into the library. Every library I have uses stuff from the standard library (like std::string) or MFC stuff (like CString). Does the last part of your answer mean that if I can link, then I will most likely be fine? When I look around at libraries on the net, they will often say VS2005 or VS2008 for their version, but not the actual CRT version (like 8.0.50727.4053). So obviously something that matters is different between VS2005 and VS2008, but differences within a version don't matter?
criddell
Concerning static linkage the linker should yield some warnings if anything goes wrong. If you are using DLLs and pass over STL types, the linker may not determine the correct runtime version and your application will crash at runtime. If you are using DLLs these DLLs normally will also work with a newer build of the runtime DLLs, unless the DLL relies on some runtime bugs or Microsoft changes type defintion. So, normally it should be safe to change runtime DLLs if the version stays the same, but the only way to be sure is not to pass STL types or to recompile.
Bernd