cwindowsc99software-distribution

Required Dependencies for Redistribution of pure C (NOT C++) Library


Background:

I am currently writing a .dll library using Visual C (NOT C++) which intends to provide performance-optimized functionalities for other applications. All functions in this library fulfill the following requirements:

Furthermore:

Question:

Assuming my previous assumptions are incorrect, which parts of the MSVC runtime do I need to include/redistribute?


Solution

  • Visual C++ is likely to pull in dependencies by default even for simple code (64-bit multiply/divide/shift when generating 32-bit code etc). If it turns out you need some of the features it provides then you have to statically link the C run-time library (/MT).

    You can also force it to not depend on anything. Compile with something like /O1 /GR- /GS- /GL /EHscr- /LD /Zl /link /NODEFAULTLIB /OPT:REF /OPT:ICF=9 kernel32.lib user32.lib.

    /Zl prevents you from using DllMain and if you actually need it you have to use DllMainCRTStartup instead. You might have to play around with the combinations of /Zl, /LD, /MT and /MD to find your sweet spot.

    Use Dependency Walker to verify that you are not linking to any *crt*/*vc* .dlls...