Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"cannot open file" compiletime error

Problem Description:

Occassionally when debugging, I get the following error. I'm using visual studio 2010:

1>------ Build started: Project: projectName, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'C:\Projects\projectName\Debug\projectName.exe'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Note that projectName is the name of my project. The error occurs when I debug, make changes, and debug again (after doing all of that, the above error shows up instead of running the program a second time).

Steps to replicate:

  1. Create a new empty c++ project, and add a file called "main.cpp" to the sources folder
  2. Copy the following code into main.cpp:

    int main(){
        return 0;
    }
    
  3. Click the green debug arrow button, and note the successful run of the program. Ensure it is closed and that the debugging session is over. Open the process explorer and ensure the exe for the project is no longer running (if it is, wait until it closes).
  4. Erase the contents of main.cpp and replace it with this code (or any other code that will compile properly which is different than the code used above):

    #include<iostream>
    int main(){
        std::cout<<"hello\n";
        return 0;
    }
    
  5. Click the green debug arrow button. Instead of running the program, the IDE will show the fatal LNK1104 error. You've now replicated the problem.

Any ideas on how to fix this?


Additional Details:

  • If I try to change the permissions or delete projectName.exe after the error has occured, an error popup shows up which says:

    You need permission to perform this action

    You require permission from the computer's administrator to make changes to this file

  • I am using windows 7.

  • The account I'm using is an admin account, but this issue also occurs exactly the same when I use a non-admin account.

  • For 2-3 minutes after the error occurs, I cannot rebuild or debug the project, but after approximately that amount of time, I am able to start at the beginning of the repro steps again.


UPDATE: BOUNTY

Anyone who can offer a solution that fixes the problem gets 100 rep :)

I've tried stopping all services, processes and applications that could be interfering with VC++ accessing the file, and the issue is still occuring. Also, running vc++ as an admin does not help.

like image 224
Cam Avatar asked May 05 '26 09:05

Cam


2 Answers

This is most likely a bugfeature of the Windows Explorer.

Make sure that the .exe file is NOT selected/focused in the Windows explorer. On Vista i often get LNK1104-errors, when the executable file is selected in the Windows Explorer during linking.

If that does not help, check that no other program has "selected" the file.

EDIT: This program can show you which process has locked your file (the pages contains some links to other "unlock" tools aswell)

like image 93
smerlin Avatar answered May 07 '26 02:05

smerlin


I had this problem with a new program I was writing that seemed to compile once but gave your error at the end of compilation and on subsequent builds. My Antiviral program, BitDefender, had locked the exe file. My exe was in the list of viruses found. I turned off Bitdefender for 5 minutes, recompiled and the program was not locked when Bitdefender restarted or thereafter.

like image 27
Steve Avatar answered May 07 '26 02:05

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!