Share via

Visual C++ Activity

Sid Kraft 31 Reputation points
2026-03-13T14:04:04.1233333+00:00

Two questions: 1.) running an app in visual C, after I make changes, re-build and execute, sometimes when I try to re-do, it gets a linker error that says "cannot write to the object file", what causes this.

2.) I deleted the .vs file and then ran visual C again, loaded the source file and now trying to build the object file but will not allow this. If I create a new C++ console app, system creates the minimum file and allows me to enter information or change info. However, cannot copy in my source file .vs, how do I copy a source file into an existing console app? Sid Kraft

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Jack Dang (WICLOUD CORPORATION) 15,610 Reputation points Microsoft External Staff Moderator
    2026-03-20T07:32:28.7566667+00:00

    Hi @Sid Kraft ,

    I will demonstrate it to make it clear for you:

    First, I created a project.

    image

    As you can see, there’s nothing in it. In the project’s folder, I created a new .cpp file.

    image

    Then, I returned to the Solution Explorer window and right-clicked the project solution -> Add -> Existing Item….

    enter image description here

    You can see that the file was added successfully. Give it a try.

    enter image description here

    I am using Visual Studio 2026. If there are any problems, I would suggest repairing your current version of VS or installing a fresh copy of Visual Studio 2026.

    I hope this clarifies your situation.If my answer was helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.

    0 comments No comments

  2. Jack Dang (WICLOUD CORPORATION) 15,610 Reputation points Microsoft External Staff Moderator
    2026-03-16T06:25:11.4533333+00:00

    Hi @Sid Kraft ,

    Thanks for reaching out.

    For question 1, I would suggest closing any running instances of your program, stopping debugging in Visual Studio, and then doing Build -> Clean Solution followed by Build -> Rebuild Solution.

    Check that your project folder isn’t read-only, and temporarily disable antivirus or backup programs that might lock files.

    Restarting Visual Studio or your PC can also help release locked files.

    Deleting the Debug or Release folders can force a full rebuild, but cleaning and rebuilding is usually enough.

    For question 2, I would suggest creating a new console project for a clean setup, then adding your old source file to it so it’s part of the build.

    Make sure any headers or libraries your code depends on are correctly referenced in the project settings.

    You can add files by right-clicking the Source Files folder -> Add -> Existing Item…, or by dragging the .cpp file into the Source Files section in Solution Explorer.

    After that, clean and rebuild the project, then run it.

    Hope this helps! If my answer was helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.


  3. Marcin Policht 83,190 Reputation points MVP Volunteer Moderator
    2026-03-13T14:07:30.62+00:00

    AFAIK, the linker error “cannot write to the object file” usually happens when the build system cannot overwrite the existing .obj or .exe file. A common cause is that the previous program instance is still running or being held open by the debugger. When the executable is running, Windows locks it, and the linker cannot replace the file during the next build. Closing the running program, stopping debugging in Visual Studio, or ending the process in Task Manager typically resolves it. Another possibility is that a file in the build directory is marked read-only, or another program such as antivirus is temporarily locking it. Cleaning the build directory (Build → Clean Solution) or deleting the Debug or Release folder forces Visual Studio to regenerate the object files.

    Deleting the .vs folder normally does not affect the ability to build source files. That folder only stores Visual Studio workspace settings, caches, and user-specific configuration. If you opened only the .cpp file instead of the project or solution file (.vcxproj or .sln), Visual Studio may treat the file as a standalone text file rather than part of a project, and it will not compile it as part of a build. The correct workflow is to open the project/solution and ensure the source file is included in the project.

    To add your existing source file to a console project, open the project in Visual Studio, then in Solution Explorer right-click the “Source Files” folder and choose “Add → Existing Item…”. Select your .cpp file and it will become part of the build. Alternatively you can copy the file into the project directory and then add it through Solution Explorer.

    Another method is to drag the .cpp file from File Explorer directly into the “Source Files” section of the project in Solution Explorer. Visual Studio will then compile it when you build the project. If you only paste the file into the folder on disk but do not add it to the project, the compiler will ignore it. The key point is that the file should appear under the project’s source files list so the build system includes it in compilation.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.