I have a number of native C++ libraries (Win32, without MFC) compiling under Visual Studio 2005, and used in a number of solutions.
I'd like to be able to choose to compile and link them as either static libraries or DLLs, depending on the needs of the particular solution in which I'm using them.
What's the best way to do this? I've considered these approaches:
EDIT: In case someone suggests it, I've also tried a more "clever" version of #3, in which I define a .vsprops containing a UserMacro called "ModuleConfigurationType" with a value of either "2" (DLL) or "4" (static library), and changed the configuration in the .vcproj to have ConfigurationType="$(ModuleConfigurationType)"
. Visual Studio silently and without warning removes the attribute and replaces it with ConfigurationType="1"
. So helpful!
Am I missing a better solution?
When your DLL refers to an external content (like function or variable), it is resolved at linking time - together with all dependencies. But that's all. If your static library has a function named print_sample_string() , but your DLL does not use it, it won't be attached to DLL image.
Yes, the Core and Utils code will be duplicated. Instead of building them as static libs you can build them as dlls and use anywhere.
LIB is a static library where functions and procedures can be placed and called as the application is being compiled. A DLL or Dynamic Link Library does the same function but is dynamic in a sense that the application can call these libraries during run-time and not during the compilation.
Yes for instance when you call windows functions from within your static lib they are normally from some dynamic library so there should be no difference.
I may have missed something, but why can't you define the DLL project with no files, and just have it link the lib created by the other project? And, with respect to settings, you can factor them out in vsprop files...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With