引用 link.exe 的奇怪 VC 链接器错误 LNK1107

发布于 2024-11-15 04:23:32 字数 1603 浏览 2 评论 0原文

我出现了一个非常奇怪的链接器错误:

link.exe : fatal error LNK1107: invalid or corrupt file: cannot read at 0x270

但这很奇怪,因为通常错误消息会告诉您哪个对象无效或损坏。换句话说,通常此错误消息看起来像这样:

myDLL.dll : fatal error LNK1107: ....

但是,在这种情况下,无效对象是正在运行的应用程序本身 (link.exe)!

我尝试用我知道有效的另一个副本替换可执行文件。同样的错误。

我运行的命令是这样的:

../vendor/microsoft/msdev80_2005/VC/bin/link.exe /NOLOGO /SUBSYSTEM:CONSOLE /LIB
PATH:../vendor/microsoft/msdev80_2005/VC/atlmfc/lib /LIBPATH:../vendor/microsoft
/msdev80_2005/VC/lib /LIBPATH:../vendor/microsoft/msdev80_2005/VC/PlatformSDK/Li
b /LIBPATH:lib/win32/dbg /OUT:bin/win32/dbg/bugshow.exe Advapi32.lib ws2_32.lib
bugshow/obj/win32/dbg/main.o libA.lib libB.lib libC.lib libD.lib

main.o 正在使用以下编译器指令进行编译:

../vendor/microsoft/msdev80_2005/VC/bin/cl.exe /nologo /X /w /EHsc -I../vendor/m
icrosoft/msdev80_2005/VC/atlmfc/include -I../vendor/microsoft/msdev80_2005/VC/in
clude -I../vendor/microsoft/msdev80_2005/VC/PlatformSDK/Include /D_WIN32 /DBOOST
_USE_WINDOWS_H /DWIN32_LEAN_AND_MEAN /D_WIN32_WINNT=0x0501 /DBOOST_THREAD_USE_LI
B /DBOOST_ALL_NO_LIB /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /Z7
/MTd /c -I../vendor/boost.org/boost/1.45.0/include /Fobugshow/obj/win32/dbg/main.o 
bugshow/main.cpp

有什么想法为什么 link.exe 会像这样失败吗?

更新:

当我将 link.exe 所在的文件夹添加到我的 PATH 中,然后调用不带路径前缀的 link.exe 时,我收到以下错误:

LINK: fatal error LNK1181: cannot open input file 'link.exe'

Why is link.exe try so badly自己打开???!?!

I am getting a really strange linker error appearing:

link.exe : fatal error LNK1107: invalid or corrupt file: cannot read at 0x270

But this is strange, because usually the error message tells you what object is invalid or corrupt. In other words, typically this error message looks something like this:

myDLL.dll : fatal error LNK1107: ....

However, in this case, the invalid object is the application itself (link.exe) that is running!

I've tried replacing the executable with another copy that I know is valid. Same error.

The command I am running is this:

../vendor/microsoft/msdev80_2005/VC/bin/link.exe /NOLOGO /SUBSYSTEM:CONSOLE /LIB
PATH:../vendor/microsoft/msdev80_2005/VC/atlmfc/lib /LIBPATH:../vendor/microsoft
/msdev80_2005/VC/lib /LIBPATH:../vendor/microsoft/msdev80_2005/VC/PlatformSDK/Li
b /LIBPATH:lib/win32/dbg /OUT:bin/win32/dbg/bugshow.exe Advapi32.lib ws2_32.lib
bugshow/obj/win32/dbg/main.o libA.lib libB.lib libC.lib libD.lib

main.o is getting compiled using the following compiler directive:

../vendor/microsoft/msdev80_2005/VC/bin/cl.exe /nologo /X /w /EHsc -I../vendor/m
icrosoft/msdev80_2005/VC/atlmfc/include -I../vendor/microsoft/msdev80_2005/VC/in
clude -I../vendor/microsoft/msdev80_2005/VC/PlatformSDK/Include /D_WIN32 /DBOOST
_USE_WINDOWS_H /DWIN32_LEAN_AND_MEAN /D_WIN32_WINNT=0x0501 /DBOOST_THREAD_USE_LI
B /DBOOST_ALL_NO_LIB /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /Z7
/MTd /c -I../vendor/boost.org/boost/1.45.0/include /Fobugshow/obj/win32/dbg/main.o 
bugshow/main.cpp

Any ideas why link.exe would be failing like this?

UPDATE:

When I add the folder that link.exe resides in to my PATH, and then call link.exe without the path prefix, I get the following error instead:

LINK: fatal error LNK1181: cannot open input file 'link.exe'

Why is link.exe trying so desperately to open itself??!?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-11-22 04:23:32

我找到问题所在了!

MSVC 链接器使用了一个令人讨厌的小 ENVIRONMENT 变量(此处描述 )在 Microsoft 的 MSDN 页面上。它说:

LINK, if defined, prepends arguments in the command line.

我的系统将环境变量LINK定义为STATIC,由我最近安装的一个应用程序定义。这导致 link.exe 将其自身的命令行实例解释如下:

STATIC link.exe /NOLOGO /SUBSYSTEM:CONSOLE ...

换句话说,通常是第一个命令行参数的 *argv[1] 实际上是 link.exe。它基本上将所有论点都降低了一个偏移量。这反过来又导致 link.exe 尝试将自身解释为它的第一个输入文件!

绝对,令人难以置信的令人沮丧且难以发现问题......

I figured out the problem!

There is a nasty little ENVIRONMENT variable that the MSVC linker uses (described here) on Microsoft's MSDN page. It says:

LINK, if defined, prepends arguments in the command line.

My system had the environment variable LINK defined as STATIC by a recent application I installed. This caused link.exe to interpret the command-line instantiation of itself as follows:

STATIC link.exe /NOLOGO /SUBSYSTEM:CONSOLE ...

In other words, *argv[1] which is usually the first command line parameter, was actually link.exe. It basically bumped all the arguments down by one offset. This in turn caused link.exe to try and interpret itself as its first input file!

Absolutely, unbelievably frustrating and hard to detect problem...

漫雪独思 2024-11-22 04:23:32

我读到,当您在链接器中包含头文件(.h)时,它会产生此错误。我遇到了这个问题并通过删除 Linker > 中的 .h 解决了它输入>添加依赖项

I read that it produces this error when you've included a header file (.h) in your Linker. I had this problem and solved it by removing the .h in Linker > Input > Addtl Dependencies

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文