为什么致命错误 “LNK1104: 无法打开文件 'C:\Program.obj'”当我编译 C++ 时发生Visual Studio 中的项目? (2)

发布于 2024-11-14 00:35:13 字数 616 浏览 4 评论 0原文

这确实是对这个标题的原始问题的后续,但我太菜鸟了,不允许在那里发表评论(你可以将其合并为评论迈克吗?)

我只是花了大约一天的时间试图弄清楚为什么我得到了当我将 VS 2010 中的命令行逐字剪切并粘贴到批处理文件中并尝试运行它时,出现了这个问题。

我将 link.exe 的完整路径放入名为“link”的批处理文件中的环境变量中,并运行命令:

“%link%”/VERBOSE ... yada yada yada

并收到错误“LNK1104:无法打开文件” 'C:\Program.obj'”。

这是因为 VS 2010 link.exe 使用 %link% 作为链接的附加输入。

由于我的 %link% var 是程序 FQN“C:\Program Files\Micro$ Visual Studio 10.0...”(即包含空格),因此链接器尝试包含“C:\Program”(作为第一个空格分隔的字符串) ),并添加了后缀“.obj”,因为它假定这就是我的意思。

然后,它尝试将这个虚假文件作为输入包含进来,但未能找到它,然后摔倒了。

作为一个海湾合作委员会人,这种行为至少可以说是出乎意料的。

简单的解决方案是为我的命令变量使用不同的名称 - 例如 %lcmd%

This is really a follow up to the original question with this title but I am too noob to be allowed to comment there (can you merge this in as a comment Mike ?)

I just spent around a day trying to work out why I was getting this problem when I cut and pasted the command line verbatim from VS 2010 into a batch file and tried to run it.

I put the full path to link.exe in an env var in the batch file called "link" and ran the command as:

"%link%" /VERBOSE ... yada yada yada

and got the error “LNK1104: cannot open file 'C:\Program.obj'”.

This is because %link% is used by VS 2010 link.exe as additional input for linking.

As my %link% var was the program FQN "C:\Program Files\Micro$ Visual Studio 10.0..." (i.e. contains spaces), the linker tried to include "C:\Program" (as the first space delimited string), and added a suffix of ".obj" because it assumed that is what I meant.

It then tried to include this spurious file as an input, failed to find it, and fell over.

Being more of a gcc man myself, this behaviour was unexpected to say the least.

The trivial solution was to use a different name for my command variable - eg %lcmd%

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

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

发布评论

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

评论(2

乖乖兔^ω^ 2024-11-21 00:35:13

Windows 引用可能是一个巨大的痛苦,因为它不是由 shell 处理,而是由单独的程序处理。您可能需要在 %link% 本身的定义中包含适当的引号。

Windows quoting can be a royal pain because rather than being handled by the shell, it's handled by individual programs. You may need to include appropriate quotes in the definition of %link% itself.

魂牵梦绕锁你心扉 2024-11-21 00:35:13

当您对项目属性中存在的链接器设置进行更改时,可能会发生此错误。当您修改该路径时,只需在“”(双引号)中给出该路径例如“c:\ Program file \〜 ”

This error may occur when you make changes in the Linker settings which is present on the properties of the project .When you modified that path just give that path in ""(double quotes) e.g "c:\Program file\~"

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