Ask a questionAsk a question
 

AnswerC++ express 2008 (error)

  • Saturday, October 31, 2009 3:37 AMspacewater Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    1>------ Build started: Project: Learn C++, Configuration: Debug Win32 ------
    1>Linking...
    1>LINK : fatal error LNK1168: cannot open C:\Users\Hojin\Documents\Visual Studio 2008\Projects\Learn C++\Debug\Learn C++.exe for writing
    1>Build log was saved at "file://c:\Users\Hojin\Documents\Visual Studio 2008\Projects\Learn C++\Learn C++\Debug\BuildLog.htm"
    1>Learn C++ - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    I often get this message when I compile the codes.  I usually close and restart to get rid of this problem but it's getting annoying. Can someone please tell me what I have to do to get rid of this error whenever it surface again?  I've tried to save the file before compiling it but it still gives me this error message.

Answers

  • Saturday, October 31, 2009 7:58 AMLlelan D. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This indicates that the exe is still running or held open by some other process. Windows is lousy at reporting what is holding an executable open. First check to see that the exe actually exited and is not still open after an exception. Make sure any spawned threads have actually shut down and that communicating with any linked libraries is not keeping a thread active. Failure to follow documented shutdown procedures for some APIs can stop an executable from shutting down. Since the name of your executable is "Learn C++.exe", I assume that you are not spawning threads or using external APIs.

    There was a problem at one point with the Subsystem for Unix Applications (SUA) and the related SDK, but that was two years ago. I never saw a documented solution to this outside of uninstalling both SUA and the SDK.

    There are a few mentions of this problem in forum archives, but each time the MS development team responds that they can not recreate the problem, do not offer any assistance to diagnose the problem in your specific environment, and never answer that thread again leaving the problem forever open.

    You can try to re-boot your OS clean or in safe mode and see if the problem persists. If not, then it might be interference from some other software that was not loaded in that mode.

    If it still does, it might be due to damaged access rights in the registry or your file system. There is a procedure for Vista that can help with this.

    I know it's not much, but I hope that helps.
  • Saturday, October 31, 2009 4:04 PMWayneAKing Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This can occur easily if you have run the program you are creating
    from the IDE, and then try to make a change to it and rebuild while
    the current execution has not finished. Example:

    Create a simple console app such as "Hello, World!".

    Add a line to the end which is intended to keep the console window
    open, such as

    system("pause");

    Build the program.

    If error free, run the program using Ctrl-F5 or the "Start Without Debugging"
    menu item.

    A console window will open with "Hello, World!" displayed,
    and the words "Press any key to continue . . ."
    from the system("pause").

    Do NOT press any key, just click on the IDE to switch back to
    your source.

    Make a simple change to your source, such as adding a comment.

    Press F7 to rebuild.

    You should get the LNK1168 error.

    Your exe cannot be overwritten because the last execution you ran has
    not ended. To fix in such a case, switch back to the open console
    window which is waiting for you to press any key. Press any key,

    You will likely get the same message again, as running with Ctrl-F5
    pauses at the end giving the same message. If so, just press any
    key again to close the open console window.

    Moral: Always ensure that your program has finished running completely
    before trying to rebuild.

    Some notes on different scenarios:

    If you do NOT have a line at the end of your program to force a wait, and run
    using Ctrl-F5 then you can rebuild as your program has actually finished at
    the point when the message appears. However, this can get confusing as you
    will wind up with more than one console window open. Always close any open
    console windows from your program before trying to rebuild.

    If your program is a GUI app (not console) ensure that you end its
    execution before trying to rebuild.

    If you run your program with debugging, and it is still executing when you
    try to do a rebuild, you should get a popup message box asking if you want
    to stop debugging.

    - Wayne

All Replies

  • Saturday, October 31, 2009 7:58 AMLlelan D. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This indicates that the exe is still running or held open by some other process. Windows is lousy at reporting what is holding an executable open. First check to see that the exe actually exited and is not still open after an exception. Make sure any spawned threads have actually shut down and that communicating with any linked libraries is not keeping a thread active. Failure to follow documented shutdown procedures for some APIs can stop an executable from shutting down. Since the name of your executable is "Learn C++.exe", I assume that you are not spawning threads or using external APIs.

    There was a problem at one point with the Subsystem for Unix Applications (SUA) and the related SDK, but that was two years ago. I never saw a documented solution to this outside of uninstalling both SUA and the SDK.

    There are a few mentions of this problem in forum archives, but each time the MS development team responds that they can not recreate the problem, do not offer any assistance to diagnose the problem in your specific environment, and never answer that thread again leaving the problem forever open.

    You can try to re-boot your OS clean or in safe mode and see if the problem persists. If not, then it might be interference from some other software that was not loaded in that mode.

    If it still does, it might be due to damaged access rights in the registry or your file system. There is a procedure for Vista that can help with this.

    I know it's not much, but I hope that helps.
  • Saturday, October 31, 2009 4:04 PMWayneAKing Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This can occur easily if you have run the program you are creating
    from the IDE, and then try to make a change to it and rebuild while
    the current execution has not finished. Example:

    Create a simple console app such as "Hello, World!".

    Add a line to the end which is intended to keep the console window
    open, such as

    system("pause");

    Build the program.

    If error free, run the program using Ctrl-F5 or the "Start Without Debugging"
    menu item.

    A console window will open with "Hello, World!" displayed,
    and the words "Press any key to continue . . ."
    from the system("pause").

    Do NOT press any key, just click on the IDE to switch back to
    your source.

    Make a simple change to your source, such as adding a comment.

    Press F7 to rebuild.

    You should get the LNK1168 error.

    Your exe cannot be overwritten because the last execution you ran has
    not ended. To fix in such a case, switch back to the open console
    window which is waiting for you to press any key. Press any key,

    You will likely get the same message again, as running with Ctrl-F5
    pauses at the end giving the same message. If so, just press any
    key again to close the open console window.

    Moral: Always ensure that your program has finished running completely
    before trying to rebuild.

    Some notes on different scenarios:

    If you do NOT have a line at the end of your program to force a wait, and run
    using Ctrl-F5 then you can rebuild as your program has actually finished at
    the point when the message appears. However, this can get confusing as you
    will wind up with more than one console window open. Always close any open
    console windows from your program before trying to rebuild.

    If your program is a GUI app (not console) ensure that you end its
    execution before trying to rebuild.

    If you run your program with debugging, and it is still executing when you
    try to do a rebuild, you should get a popup message box asking if you want
    to stop debugging.

    - Wayne