Ошибка msb6006 link exe завершилась с кодом 1168

  • Remove From My Forums
  • Вопрос

  • Подскажите пожалуйста. Пишу исходник в Microsoft Visual C++ 2008 Express Edition. Компилирую — все нормально, работает. вношу какие либо изменения в коде и пытаюсь заново скомпилировать. Выдает вот такую ошибку.

    1>—— Построение начато: проект: 5_stepen’, Конфигурация: Debug Win32 ——
    1>Компиляция…
    1>stepen’.cpp
    1>Компоновка…
    1>LINK : fatal error LNK1168: не удается открыть C:UsersAntonDocumentsVisual Studio 2008Projects5_stepen’Debug5_stepen’.exe для записи
    1>Журнал построения был сохранен в «file://c:UsersAntonDocumentsVisual Studio 2008Projects5_stepen’5_stepen’DebugBuildLog.htm»
    1>5_stepen’ — ошибок 1, предупреждений 0
    ========== Построение: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ==========

    Для устранения приходится сохранить мой.cpp и закрыть прогу. через 2 минуты отрывать. тогда запускается компиляция. Ни чего не могу поделать.

    • Перемещено

      2 октября 2010 г. 0:53
      MSDN Forums Consolidation (От:Visual Studio — отзывы и пожелания)

Ответы

  • Добрый день.

    Такое происходит, когда Ваш файл 5_stepen.exe не доступен для записи. В ОС WinNT это ситуация возникает, когда файл залочен. Причиной может служить следующее: Вы скомпилировали проект и запустили полученный код. Вносите изменения, компилируете, но запись в файл .exe линковщиком не может быть выполнена, т.к. программа продолжает выполняться, т.е. она продолжает висеть в памяти. Для решения проблемы необходимо просто остановить выполнение Вашей программы 5_stepen.exe.

    • Помечено в качестве ответа
      -An-
      9 мая 2010 г. 19:15

Студворк — интернет-сервис помощи студентам

Подскажите пожалуйста,что значит эта ошибка?

1>—— Построение начато: проект: Курсовая лаба, Конфигурация: Debug Win32 ——
1>Компоновка…
1>LINK : fatal error LNK1168: не удается открыть C:UsersБогданDocumentsVisual Studio 2008ProjectsИрусяКурсовая лабаDebugКурсовая лаба.exe для записи
1>Журнал построения был сохранен в «file://c:UsersБогданDocumentsVisual Studio 2008ProjectsИрусяКурсовая лабаКурсовая лабаDebugBuildLog.htm»
1>Курсовая лаба — ошибок 1, предупреждений 0
========== Построение: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ==========

In this guide, we will walk you through the process of resolving the Link Fatal Error LNK1168 — Cannot Open Issue. This error is commonly encountered by developers using Microsoft Visual Studio when attempting to build or compile their projects.

Table of Contents

  • Understanding Link Fatal Error LNK1168
  • Step-by-Step Solution
  • FAQs

Understanding Link Fatal Error LNK1168

Link Fatal Error LNK1168 occurs when the linker is unable to open the specified file for writing. This may happen for a variety of reasons, such as the file being in use by another process, the file being read-only, or the user not having the necessary permissions to modify the file.

The error message typically looks like this:

LINK : fatal error LNK1168: cannot open [filename].exe for writing

To resolve this error, you need to identify the cause and follow the appropriate steps to fix it.

Step-by-Step Solution

Close any running instances of the program: If the program you are trying to build is currently running, Visual Studio will not be able to overwrite the existing .exe file. Close the running program and try to build your project again.

Check for file access issues: If the error persists, verify that the file is not marked as read-only or locked by another process. To do this, right-click on the file, select «Properties», and ensure that the «Read-only» checkbox is not ticked.

Run Visual Studio as an administrator: If you’re still encountering the error, it’s possible that you lack the necessary permissions to modify the file. Running Visual Studio as an administrator can help resolve this issue. To do this, right-click on the Visual Studio icon and select «Run as administrator».

Check for antivirus interference: Some antivirus programs may block Visual Studio from accessing certain files. Try temporarily disabling your antivirus software and rebuilding your project.

Delete the .exe file manually: If none of the above steps work, try deleting the .exe file manually from the project’s output directory. Once the file is deleted, rebuild your project.

FAQs

1. What is Visual Studio Linker?

The Visual Studio linker is a tool that combines the compiled code and resources from multiple input files into a single executable file. It is responsible for resolving external references, generating debug information, and performing optimizations.

2. Why am I getting a Link Fatal Error LNK1168?

Link Fatal Error LNK1168 occurs when the linker is unable to open the specified file for writing. This may be due to the file being in use by another process, the file being read-only, or the user not having the necessary permissions to modify the file.

3. Can I ignore Link Fatal Error LNK1168?

No, you cannot ignore Link Fatal Error LNK1168. It is a fatal error that prevents the linker from generating the final executable file. You must resolve the issue before you can successfully build your project.

4. How can I prevent Link Fatal Error LNK1168 from occurring in the future?

To prevent Link Fatal Error LNK1168 from occurring in the future, ensure that your project’s output files are not in use by other processes, have the necessary permissions to modify the files, and keep your antivirus software updated and configured to avoid conflicts with Visual Studio.

5. What other link errors might I encounter in Visual Studio?

There are several other link errors that you may encounter in Visual Studio, such as LNK1104 (cannot open file), LNK2001 (unresolved external symbol), and LNK2019 (unresolved external symbol). Each error has its own specific causes and solutions.

  • Microsoft Docs: Linker Tools Error LNK1168
  • Stack Overflow: Visual Studio Error LNK1168
  • Microsoft Visual Studio: Official Site

Suddenly, my Visual Studio Express 2010 C++ stopped rebuilding my project.
When I first hit F7 the project builds and runs fine (heck, it’s a hello world example).

Then I make some changes and hit F7 again, then I get:

1>LINK : fatal error LNK1168: cannot open C:UsersusernameDocumentsVisual Studio 2010ProjectsconsoleDebugconsole.exe for writing**<br><br>

Now the funny thing comes:

  1. The app is not running and it’s not shown in the Task Manager.
  2. Going into the project directory and trying to remove it with hands comes with success but the file APPEARS AGAIN FROM NOWHERE.
  3. The system restore is disabled.
  4. I also tried to take the ownership of the whole damn drive.
  5. Every time I delete the file it recreates itself again but sometimes it stops doing that.
  6. If I delete the file (and it recreates after that), and then I start sysinternals procmon then the file disappears.
  7. If I start procmon before — then the file keeps appearing after delete like always.

OS: W7 SP1 64-bit, with latest updates

Any ideas, please?

Amal K's user avatar

Amal K

4,2692 gold badges19 silver badges44 bronze badges

asked Aug 25, 2012 at 17:25

gogiii's user avatar

1

The problem is probably that you forgot to close the program and that you instead have the program running in the background.

Find the console window where the exe file program is running, and close it by clicking the X in the upper right corner. Then try to recompile the program. In my case this solved the problem.

I know this posting is old, but I am answering for the other people like me who find this through the search engines.

answered Jul 6, 2013 at 6:53

CodeMed's user avatar

CodeMedCodeMed

9,39569 gold badges208 silver badges361 bronze badges

7

I’ve encountered this problem when the build is abruptly closed before it is loaded. No process would show up in the Task Manager, but if you navigate to the executable generated in the project folder and try to delete it, Windows claims that the application is in use. (If not, just delete the file and rebuild, which generates a new executable)
In Windows(Visual Studio 2019), the file is located in this directory by default:

%USERPROFILE%sourcereposProjectFolderNameDebug

To end the allegedly running process, open the command prompt and type in the following command:

taskkill /F /IM ApplicationName.exe

This forces any running instance to be terminated.
Rebuild and execute!

answered Sep 17, 2019 at 16:20

Amal K's user avatar

Amal KAmal K

4,2692 gold badges19 silver badges44 bronze badges

1

Restarting Visual Studio solved the problem for me.

answered Jan 7, 2017 at 18:15

Aleksei Mialkin's user avatar

Aleksei MialkinAleksei Mialkin

2,2271 gold badge27 silver badges25 bronze badges

1

In my case, cleaning and rebuilding the project resolved the problem.

Uli Köhler's user avatar

Uli Köhler

12.9k15 gold badges69 silver badges120 bronze badges

answered Mar 2, 2014 at 15:35

Hau Le's user avatar

Hau LeHau Le

1211 silver badge5 bronze badges

If the above solutions didn’t work, you can try this which worked for me.

Open an elevated command prompt (cmd -> Run as administrator), then write following command and hit enter:

wmic process where name='YOUR_PROCESS_NAME.exe' delete

If you see a message: Instance deletion successful., then you will be again able to build and run project from VS.

e.g. in OP’s case, the command will be:

wmic process where name='console.exe' delete

answered Aug 3, 2021 at 9:06

UkFLSUI's user avatar

UkFLSUIUkFLSUI

5,4716 gold badges32 silver badges47 bronze badges

This solved same problem I also came across very well

  1. Close the app if it is still running on the taskbar,
  2. Open cmd (command prompt) and run the following
taskkill /F /IM ApplicationName.exe
  1. Rebuild your project!! error solved!

cs1349459's user avatar

answered Sep 25, 2022 at 1:11

nios's user avatar

niosnios

911 silver badge7 bronze badges

well, I actually just saved and closed the project and restarted VS Express 2013 in windows 8 and that sorted my problem.

answered Apr 8, 2015 at 17:50

Sparsh Jain's user avatar

2

The Reason is that your previous build is still running in the background.
I solve this problem by following these steps:

  • Open Task Manager
  • Goto Details Tab
  • Find Your Application
  • End Task it by right clicking on it
  • Done!

answered Aug 4, 2020 at 12:48

Back2Lobby's user avatar

Back2LobbyBack2Lobby

5036 silver badges12 bronze badges

This can also be a problem from the improper use of functions like FindNextFile when a FindClose is never executed. The process of the built file is terminated, and the build itself can be deleted, but LNK1168 will prevent a rebuild because of the open handle. This can create a handle leak in Explorer which can be addressed by terminating and restarting Explorer, but in many cases an immediate reboot is necessary.

answered Oct 9, 2015 at 2:44

Laurie Stearn's user avatar

Laurie StearnLaurie Stearn

9611 gold badge12 silver badges33 bronze badges

I know this is an old question but thought I’d share how I resolved the issue.

If you’re using Visual Studio and this error occurs, you can try to attach to process (CTRL+ALT+P) and find the «(program).exe» process. When you try to attach to it, an error will display stating that it failed to attach which removes the process from «running» (even though it’s not…) You’ll also be able to delete the (program).exe from your Debug folder.

Hope this helps someone! :)

answered Oct 4, 2019 at 5:25

tw1tch01's user avatar

tw1tch01tw1tch01

491 silver badge4 bronze badges

FINALLY THE BEST WAY WORKED PERFECTLY FOR ME

None of the solutions in this page worked for me EXCEPT THE FOLLOWING

Below the comment sections of the second answer, try the following :

Adding to my above comment, Task Manager does not display the
filename.exe process but Resource Monitor does, so I’m able to
kill it from there which solves the issue without having to reboot.
A__ Jun 19 ’19 at 21:23

answered Aug 14, 2020 at 14:32

Sam's user avatar

SamSam

3493 silver badges11 bronze badges

If none of the above suggested work for you, which was the case for me, just change the project name. It creates a new exe in the new project name. Later when you restart, you can change it back to your original project name.

answered Aug 22, 2021 at 9:43

Rathnavel's user avatar

RathnavelRathnavel

751 silver badge14 bronze badges

I know this is an old thread but I was stumbling in the same problem also. Finding it in task manager is tricky, and I started to grow tired of having to restart my PC every time this happened.

A solution would be to download Process Explorer and there you can search for running tasks. In my case I was having the following error:

1>LINK : fatal error LNK1168: cannot open C:OutBuildVS12_appDebugplatform_test.exe for writing [C:BuildVS12_appplatform_test.vcxproj]

I searched for C:OutBuildVS12_appDebugplatform_test.exe in Process Explorer, killed it and I was able to compile.

answered Sep 15, 2022 at 11:15

Ra'w's user avatar

Ra’wRa’w

1132 silver badges10 bronze badges

I also had this same issue. My console window was no longer open, but I was able to see my application running by going to processes within task manager. The process name was the name of my application. Once I ended the process I was able to build and compile my code with no issues.

answered Sep 12, 2013 at 23:54

Jason's user avatar

JasonJason

1241 gold badge3 silver badges11 bronze badges

Start your program as an administrator. The program can’t rewrite your files cause your files are in a protected location on your hard drive.

Joonatan's user avatar

answered Jan 6, 2014 at 15:07

chosen's user avatar

0

Иногда, когда я пытаюсь скомпилировать свой проект, VisualStudio показывает мне эту ошибку:

1> ССЫЛКА: фатальная ошибка LNK1168: невозможно открыть C: Path myfile.exe для записи

И это не позволило мне скомпилировать проект.

Кажется, что myfile.exe еще открыт и работает в фоновом режиме, хотя я его закрыл. Я открыл Win TaskManager, но файл не отображается в списке запущенных процессов.

Эта ошибка сохраняется, и единственное решение, которое я нашел, — это перезагрузить систему, но это утомительный способ, который сводит меня с ума, потому что эта ошибка часто повторяется.

Есть идеи по ее устранению? У кого-то раньше была такая же ошибка?

2 ответа

Лучший ответ

У меня уже много раз возникала эта ошибка. Хотя ваш myfile.exe не отображается в TaskManager, он еще присутствует в фоновом режиме. Если вы откроете cmd как администратор и наберете:

список задач | НАЙТИ «myfile.exe»

Вы можете увидеть, как работает ваш процесс.

Итак, теперь введите команду:

taskkill / IM myfile.exe / F

Чтобы заставить процесс убить.

Теперь, если вы снова попытаетесь скомпилировать свой проект, вы увидите, что с компилятором все в порядке, и ошибка устранена.

Конечно, возможно, что эта ошибка повторится снова, поэтому я предлагаю вам создать файл .bat, который запускает команду kill, чтобы вы могли быстро решить проблему.


0

LolloAAA
22 Ноя 2020 в 15:54

Касательно: LNK1168

У Microsoft есть веб-страница, посвященная этой ошибке:

LNK1168

Первое, что находится на связанной странице:

The linker can’t write to filename.

Остальная часть страницы обсуждает детали того, почему компоновщик не может записывать в файл.


0

user3629249
24 Ноя 2020 в 01:23

Понравилась статья? Поделить с друзьями:
  • Ошибка msb6006 link exe завершилась с кодом 1120
  • Ошибка msa на xiaomi как убрать
  • Ошибка ms windows store assoc
  • Ошибка ms settings display этому
  • Ошибка ms gamingoverlay windows 11