仅在Windows 10上相对于.exe链接.lib时崩溃 [英] Crash when linking with .lib relative to an .exe on windows 10 only

查看:62
本文介绍了仅在Windows 10上相对于.exe链接.lib时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当创建一个与依赖于可执行文件的可执行文件或库链接的应用程序时,此应用程序在Windows 10上崩溃。
$


有关此问题的讨论stackoverflow上的主题(https://stackoverflow.com/questions/45819855/call-of-statically-link-function-crash-everytimes-on-windows-8-10-but-not-7)。



在总结中,我可以引用RbMm:



"Windows 10崩溃的根源 - 因为Windows 10无法解析PE ("exe")如果此pe没有标志IMAGE_FILE_DLL则导入。换句话说,它像LoadLibraryEx一样使用标志DONT_RESOLVE_DLL_REFERENCES处理此PE - 不加载指定模块引用的其他
可执行模块,也不解析导入。因此,此PE未初始化并将在第一次导入函数调用时崩溃(在您的情况下,这是strcmp)。这只发生在win10上。在win 8.1(build 9600)
和win 7 import for exe文件(加载为dll)已解决。"
$


此行为调用的最简单测试来自测试exe的MatchToken,函数,从Netsh.exe导出。代码可以是下一个:

When a create an application that link with an executable or library that depends on an executable, this application crash on windows 10.

There is a discussion on this subject on stackoverflow (https://stackoverflow.com/questions/45819855/call-of-statically-link-function-crash-everytimes-on-windows-8-10-but-not-7).

In summury I can quote RbMm :

"The root of crash on windows 10 - because windows 10 not resolve PE ("exe") import if this pe have no flag IMAGE_FILE_DLL. in other words it process this PE like LoadLibraryEx with flag DONT_RESOLVE_DLL_REFERENCES - does not load additional executable modules that are referenced by the specified module and nor resolve imports. as result this PE not initialized and will crash at first import function call (in your case this is strcmp). and this is happens only on win10. on win 8.1 (build 9600) and win 7 import for exe files (loaded as dll) resolved."

The simplest test for this behavior call from test exe MatchToken, function, which exported from Netsh.exe. code can be next:

#include <Netsh.h>

#pragma comment(链接器," / defaultlib: Netsh.lib")

#pragma comment(linker, "/defaultlib:Netsh.lib")

MatchToken(L" *",L" *"); //在win 10上崩溃

MatchToken(L"*", L"*");// crash here on win 10


什么是在Windows 10上使用Netsh.lib的正确方法(或任何与可执行文件链接的lib)?
$

What is the right way to use Netsh.lib on windows 10 (or any lib linking with an executable) ?

推荐答案

感谢您在此发帖。

据我所知,Visual Studio链接器可以接受COFF标准库和COFF导入库,两者通常都具有扩展名.lib。标准库包含对象,由LIB工具创建。

As far as I know that the visual studio linker can accepts COFF standard libraries and COFF import libraries, both of which usually have the extension .lib. Standard libraries contain objects and are created by the LIB tool.

我认为Netsh.lib是标准库,您可以尝试以下步骤:

I think that the Netsh.lib is standard library, you could try the following steps:



  1. 打开项目的属性页对话框。有关详细信息,请参阅
    设置Visual C ++项目属性

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.

点击链接器文件夹。

点击输入属性页。

修改附加依赖项属性。


以编程方式将.lib文件添加为链接器输入



  • 参见< a href ="https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vclinkertool.additionaldependencies.aspx">
    AdditionalDependencies 。
  • IMAGE_FILE_HEADER结构代表COFF标题格式。 因此标准库必须包含COFF标题格式。

    The IMAGE_FILE_HEADER structure represents the COFF header format.  So the standard library must contain COFF header format.

    Best 问候,

    Best  Regards,

    Hart


    这篇关于仅在Windows 10上相对于.exe链接.lib时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆