Home > Blockchain >  Required Dependencies for Redistribution of pure C (NOT C ) Library
Required Dependencies for Redistribution of pure C (NOT C ) Library

Time:09-04

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:

  • They operate purely on built-in primitive types (int, long long, etc.), pointers to these types, or self-defined structs which in turn are comprised of these types.
  • No code segment relies on external code or libraries - not even on 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:

  • The library has no external dependencies
  • The code does not have any #include ...-statements
  • The library is written in pure C (conforming the C99 standard - apart from the __declspec(dllexport)-statement decorating some of the written functions)

Question:

  • What are the dependencies needed for redeploying/redistributing this specific library? I think that I do not need the MSVC runtime as I do not use any external types, functions, or dependencies, am I correct?

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

CodePudding user response:

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...

  • Related