Search code examples
64-bitmsvcrt

Detecting multiple linked C runtime on windows


I have some problems with one of the projects I am working on on windows (64 bits). The program sometimes crash, sometimes does not, and I suspect the problem to be linked with multiple linked C runtime. How can I detect this on windows ? I tried with depends.exe, but it did not report the CRT


Solution

  • It's rather unlikely that you could successfully statically link against multiple C runtime libraries - you would run into many symbol definition conflicts which would at least produce voluminous warnings, and only a reckless engineer would ignore them.

    With depends, I would make sure to use the dynamic profiling option, to check all dependencies for dynamic CRTLs they load. If doesn't turn up anything, I suspect your problem is elsewhere.

    I would suspect your problem is elsewhere in any case, though, as DLLs with C-level APIs shouldn't, as a rule, rely on shared state in the CRTL - most commonly the memory allocator - and should have adopt a standardized protocol for cross-API memory management, such as caller-allocates, callee-uses, or passing in memory allocation callbacks, etc. In other words, multiple CRTLs in the same process is normally not a problem due to correct use of a memory management protocol.

    For transient failures, I would suspect multithreading or heap corruption.