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

1 answer

Sort by: Most helpful
  1. Marcin Policht 82,685 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.