-1

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?

unknown6656
  • 2,765
  • 2
  • 36
  • 52
  • 1
    Are there any `#include <...>` lines in your code (where the `...` is a system header)? If so, then you *are* potentially using the VC run-time library. Even if there aren't any such headers, you *may* still have code that calls the RTL. – Adrian Mole Sep 03 '22 at 12:12
  • Nope, I do not have any includes. Furthermore, I do not call any function, which I do not have written myself (including exp, abs, min, max, ...) – unknown6656 Sep 03 '22 at 12:22
  • 1
    You might find https://github.com/lucasg/Dependencies useful. – SirDarius Sep 03 '22 at 12:31
  • Don't guess, verify. Start the developer command prompt and run dumpbin.exe /imports foo.dll. You'll get a list of all imported functions, grouped by the runtime dll they are expected to be imported from. – Hans Passant Sep 03 '22 at 12:53
  • Visual C++ is the product name, even if you are compiling C code. – Anders Sep 03 '22 at 13:07

1 Answers1

1

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

Anders
  • 97,548
  • 12
  • 110
  • 164