当我在Visual Studio中编译C ++项目时,为什么会出现致命错误"LNK1104:无法打开文件'C:\ Program.obj'"? (2) [英] Why does fatal error “LNK1104: cannot open file 'C:\Program.obj'” occur when I compile a C++ project in Visual Studio? (2)

查看:333
本文介绍了当我在Visual Studio中编译C ++项目时,为什么会出现致命错误"LNK1104:无法打开文件'C:\ Program.obj'"? (2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这确实是对带有该标题的原始问题的后续操作,但我实在是太菜鸟了,不能在那里发表评论(您可以将其合并为评论Mike吗?)

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 ?)

我花了整整一天的时间来弄清楚为什么我将VS 2010的命令行逐字剪切并粘贴到批处理文件中并尝试运行时为什么会出现此问题.

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.

我在名为"link"的批处理文件中的env var中放置了link.exe的完整路径,并以以下方式运行命令:

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

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

并显示错误"LNK1104:无法打开文件'C:\ Program.obj'".

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

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

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

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

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.

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

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

推荐答案

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.

这篇关于当我在Visual Studio中编译C ++项目时,为什么会出现致命错误"LNK1104:无法打开文件'C:\ Program.obj'"? (2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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