在Windows上检测多个链接的C运行时

时间:2020-12-04 19:52:12

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

我在Windows(64位)上工作的项目有一些问题。该程序有时会崩溃,有时不会崩溃,我怀疑问题是与多个链接的C运行时链接。如何在Windows上检测到这个?我尝试使用depends.exe,但它没有报告CRT

1 个解决方案

#1


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.

您不太可能成功地静态链接多个C运行时库 - 您将遇到许多符号定义冲突,这至少会产生大量警告,只有鲁莽的工程师会忽略它们。

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.

使用depends,我会确保使用动态分析选项来检查它们加载的动态CRTL的所有依赖项。如果没有发现任何事情,我怀疑你的问题在其他地方。

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.

我怀疑你的问题在任何情况下都是在其他地方,因为具有C级API的DLL通常不应该依赖于CRTL中的共享状态 - 最常见的是内存分配器 - 并且应该采用标准化协议跨API内存管理,例如调用者分配,被调用者使用或传入内存分配回调等。换句话说,由于正确使用内存管理协议,同一进程中的多个CRTL通常不是问题。

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

对于瞬态故障,我怀疑多线程或堆损​​坏。

#1


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.

您不太可能成功地静态链接多个C运行时库 - 您将遇到许多符号定义冲突,这至少会产生大量警告,只有鲁莽的工程师会忽略它们。

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.

使用depends,我会确保使用动态分析选项来检查它们加载的动态CRTL的所有依赖项。如果没有发现任何事情,我怀疑你的问题在其他地方。

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.

我怀疑你的问题在任何情况下都是在其他地方,因为具有C级API的DLL通常不应该依赖于CRTL中的共享状态 - 最常见的是内存分配器 - 并且应该采用标准化协议跨API内存管理,例如调用者分配,被调用者使用或传入内存分配回调等。换句话说,由于正确使用内存管理协议,同一进程中的多个CRTL通常不是问题。

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

对于瞬态故障,我怀疑多线程或堆损​​坏。