Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLLs and STLs and static data (oh my!)

OK..... I've done all the reading on related questions, and a few MSDN articles, and about a day's worth of googling.

What's the current "state of the art" answer to this question:

I'm using VS 2008, C++ unmanaged code. I have a solution file with quite a few DLLs and quite a few EXEs. As long as I completely control the build environment, such that all pieces and parts are built with the same flags, and use the same runtime libaries, and no one has a statically linked CRT library, am I ok to pass STL objects around?

It seems like this should be OK, but depending on which article you read, there's lots of Fear, Uncertainty, and Doubt.

I know there's all sorts of problems with templates that produce static data behind the scenes (every dll would get their own copy, leading to heartache), but what about regular old STL?

like image 217
Eric H. Avatar asked Jul 26 '09 14:07

Eric H.


2 Answers

We successfully pass STL objects around in our application which is made up from dozens of DLLs. To ensure it works one of our automated tests that runs at every build is to verify the settings for all projects. If you add a new project and misconfigure it, or break the configuration of an existing project, the build fails.

The settings we check are as follows. Note not all of these will cause issues, but we check them for consistency.

#defines

_WIN32_WINNT
STRICT
_WIN32_IE
NDEBUG
_DEBUG
_SECURE_SCL

Compiler options

DebugInformationFormat
WholeProgramOptimization
RuntimeLibrary
like image 39
Stephen Nutt Avatar answered Oct 14 '22 19:10

Stephen Nutt


As long as they ALL use the exact same version of runtime DLLs, there should be no problem with STL. But once you happen to have several around, they will use for instance different heaps - leading to no end of troubles.

like image 70
EFraim Avatar answered Oct 14 '22 18:10

EFraim