6

When I compile my code in visual studio c++ 2008 I get the following error:

fatal error LNK1104: cannot open file 'C:\Users\...\Documents\Visual Studio         
2008\Projects\...\Debug\....exe

I just copied my code from another project in visual studio C++ and pasted it in this project again in VS C++. Can it cause this error?

RJFalconer
  • 10,890
  • 5
  • 51
  • 66
Bahareh
  • 55
  • 1
  • 1
  • 4
  • check the read only property of this file and be sure that it is false – SimpleFrog Jan 31 '13 at 04:43
  • i had the same issue, i think you should try close the application and open it as administrator. – JonnySharp Sep 07 '14 at 10:22
  • possible duplicate of [Why does fatal error "LNK1104: cannot open file 'C:\Program.obj'" occur when I compile a C++ project in Visual Studio?](http://stackoverflow.com/questions/133698/why-does-fatal-error-lnk1104-cannot-open-file-c-program-obj-occur-when-i-c) – Jad Apr 18 '15 at 13:21

5 Answers5

7

This can happen because, for example, the executable is currently executing or opened by another program, or because you don't have the right permissions for that directory.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • Depends on the exact reason why VS can't open the file, which I am not capable of psychically determining. – Puppy Aug 20 '12 at 03:31
  • I get this problem because MS Security Essentials/Defender keeps the file locked. Unfortunately, turning off real-time protection does not help. `:-|` – Synetech Mar 15 '17 at 22:58
2

open TASK MANAGER and see if the process of the .exe is running in background even after closing it. if yes, then kill the process and then try to run it again.

ivy
  • 31
  • 5
2

This can happen if you have turned on preprocessor output, e.g. in Properties | C/C++ | Preprocessor | Preprocess to a File == YES. Creating a preprocessor output file (of file type .i) is mutually exclusive to creating an object file (of time .obj).

Henry
  • 21
  • 1
1

In my case it was caused by the "Incremental Linking" option of the projects (Visual Studio 2015). Maybe because the files were also dependencies of other projects from the same solution, not sure...

mBardos
  • 2,872
  • 1
  • 19
  • 16
  • Thank you! I have the same problem, and after search all over the place, this is the answer. I have no idea why this is the problem. My small console project only depend on a static lib (not project). – user2418216 Nov 21 '19 at 21:13
0

I had the same problem (I don't say that this is exactly your case, but still) and it was quite strange because when I changed the code a bit everything worked normally... And I just found out that my antivirus blocked the .exe file as a possible threat (idk, mb it didn't like how I worked with memory by my C++ program). So, the source of LNK1104 can also be the antivirus.