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:
int
, long long
, etc.), pointers to these types, or self-defined struct
s which in turn are comprised of these types.malloc
or free
. I do not call any functions which I have not written myself (I even rewrote functions like abs
as inline assembly code to avoid any external function calls).Furthermore:
#include ...
-statements__declspec(dllexport)
-statement decorating some of the written functions)Assuming my previous assumptions are incorrect, which parts of the MSVC runtime do I need to include/redistribute?
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...