Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building windows c++ libraries without a runtime?

I'm trying to create a c++ library for use on windows/MSVC.

My problem is that it seems that in order to link properly, I need to distribute a bunch of different versions, linked against different versions of MSVC's c++ runtimes - single and multi-threaded, debug and release, different compiler versions, various other security and other options.

I'd love to just distribute maybe two, 32 bit and 64 bit.

My idea is to maybe use a different new operator (say, mynew) and custom allocators for all my STL types. When creating the lib, /nodefaultlib. Then, when linking in from a parent project, require them to thunk mynew to new, and my stl allocator to the standard one (or one of their choosing). I guess I'd need to do delete, and a few other functions. Naturally I'd provide an example thunking implementation with the library, but this would hopefully save everyone a lot of headache.

Is this possible? Has anyone ever tried this? Is there a best practices for library creation/distribution on windows/MSVC?

like image 586
tfinniga Avatar asked Mar 02 '23 06:03

tfinniga


1 Answers

You want static linking, as a general answer.

Quick note on Chris' answer (don't want to de-boost cause it's mostly good, but...):

DO NOT link to msvcrt.dll (the unversioned one); this is the OS-specific version DLL, and if you link to it, your app probably will not work on other versions of Windows. You should always be linking to msvcrt##.dll, as far as I know. The DDK may contain a lib for it, but don't link to it unless you really know what you're doing.

like image 109
Nick Avatar answered Mar 11 '23 22:03

Nick