Why does fatal error “LNK1104: cannot open file &#

2019-08-06 17:48发布

问题:

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%

回答1:

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.



回答2:

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\~"