Permission denied to create temporary file in Visual Studio Code - c++

When I try to 'Run Build Task' in VS Code using C/C++ plugin, I get the following error:
Assembler messages:
Fatal error: can't create C:\Users\UserName\AppData\Local\Temp\cc2Ad432.o: Permission denied
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe' -g c:\Users\UserName\projects\helloworld\helloworld.cpp -o c:\Users\UserName\projects\helloworld\helloworld.exe" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
When I try to build a code in 'Code::Blocks' it displays the same error - Can't create temporary file. Permission Denied
I tried changing the value of TEMP and TMP user variables in 'Environment variables'. That solved the problem for me but it doesn't allow 'Windows Word' to create temporary files.

Related

VIsual Studio Code error cannot open output file main.exe

This is my first project with Visual Studio Code. When i go to run my "Hello World" project I get this
cd "c:\Users\imaco\Desktop\Cpppractice" && g++ main.cpp -o main && "c:\Users\imaco\Desktop\Cpppractice"main
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file main.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
my code reads
1 #include <iostream>
2
3
4
5 int main()
6 {
7 std:: cout << "Hello World!";
8 }
-I've made sure it isn't running in the background.
-I've closed and reopened the program and ran the code again with same results.
-I've allowed it as an exception in Bit Defender.
Any help would be greatly appreciated!!
I need 50 reputation to comment, otherwise I would have added a comment. I ran into this issue myself and I solved it using this. However, it worked for me:
"cannot open output file main.exe: Permission denied collect2.exe: error: ld returned 1 exit status"
It says that the permission has been denied. This probably means that you have not given execute access to visual studio in a certain folder or the file has execute restrictions. You could probably be storing this file in a folder that has restricted access. There are a couple of options:
You could probably move it to a new folder that does not have any execute access restrictions.
You may have have to change the permission of that folder/file to read, write and execute using admin privileges.
If this does not work, let me know in the comments section, because I faced the same issue of permission denied.
One of the reasons for this error is that your firewall is blocking "collect2.exe" file. In some cases the firewall is disconnected so you might need to connect with it. Hope it helps !
Try to open terminal (Ctrl + `) and type:
g++ main.cpp then
.\a.exe
(assuming the terminal opens up in your working directory)
This usually happens when VS decides to keep a chunk of code running as a separate entity in the background. A way to fix this is that since you are on Windows, I would right-click the taskbar and click on task manager. This will open up all the tasks that are currently running on the computer. Then, search for "Windows console host." You can change the sorting of the list. Once you find it you can click on it and then at the bottom right it will have an "End Task" available for you to click. Click that and then retry again.
You should be good after that, but let me know if you are still having issues.
when this occurs i usually just remove the exe file and build again

Unable to build and run c++ code in visual studio code

I have setup the correct path for mingw and am successfully able to compile my code using terminal in vscode. But when I press ctrl+shift+b to build i get the following error in my terminal
Executing task: C:\MinGW\bin\g++.exe -g 'c:\Users\Ansh Kapoor\Desktop\cpp\main.cpp' -o 'c:\Users\Ansh
Kapoor\Desktop\cpp\main.exe'<
/usr/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
whereas the same code is successfully executed when I write
g++ main.cpp -o 'main.exe'
Now I have checked the path and environment variables and all those things are correct.
The error in finding the proper path was because of using git bash as the terminal rather than windows powershell or cmd.

Permission Error when Compiling C++ code in Cygwin

I'm trying to compile a file in C++ on Cygwin but I keep getting the same error:
Hola! ~/projects/basic-cpp $ g++ main.cpp
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: reopening a.exe: Permission denied
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Permission denied
collect2.exe: error: ld returned 1 exit status
I've seen on other questions on Stack Overflow that this can be caused by the executable being currently run, but I know this is not the case. If I run the command with raised permissions it compiles, so it has something to do with not being able to create the file in the directory because it doesn't have permission.
Also, when I get it to compile by using raised permissions, the file isn't writable by the user. If I compile something using java the *.class file isn't user writable either. If I open and save a new file with emacs the file IS user writable. I feel like there's some serious permission issues with my Cygwin install and any pointers would be helpful.
I had to fully reinstall Cygwin in order to fix this. Something was seriously wrong. I'm still not sure what caused it.

jenkins while creating folder access denied using base clear case

I am trying to build make file using xshell plugin in jenkins.
Manually, I am able to build, but when I trigger from jenkins I get bellow error please suggest why access is denied:
element * CHECKEDOUT
element * /main/LATEST
[workspace] $ cmd.exe /C '""V:\dpush_view\CCAD_REPO\CC Training\my\one.bat" && exit %%ERRORLEVEL%%"'
D:\Program Files\Jenkins\jobs\nmake\workspace>v:
V:\>cd "dpush_view\CCAD_REPO\CC Training\my"
V:\dpush_view\CCAD_REPO\CC Training\my>nmake vivek1.mk
Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
mkdir "V:\dpush_view\CCAD_REPO\CC Training\ball\sree"
Access is denied.
NMAKE : fatal error U1077: 'mkdir' : return code '0x1'
Stop.
V:\dpush_view\CCAD_REPO\CC Training\my>pause
Press any key to continue . . .
Build step 'Invoke XShell command' marked build as failure
Finished: FAILURE
You need to make sure of the account used by Jenkins to use that ClearCase view.
If Jenkins runs with the system account, chances are that CLEARCASE_PRIMARY_GROUP isn't properly set, and it wouldn't have the right to fully access CCAD_REPO vobs elements.
So make sure it is running with your account (which, when used manually, can successfully build in that view).
The other aspect is in the rights associated with the parent folder where you try to create ball\sree:
Make sure (by doing a cleartool descr -l "V:\dpush_view\CCAD_REPO\CC Training##") that the folder is "executable" (755).
If not, a simple:
cleartool protect -chmod 755 "V:\dpush_view\CCAD_REPO\CC Training##"
If "V:\dpush_view\CCAD_REPO\CC Training\ball##" already exists (and Jenkins is trying to create sre within ball folder, repeat the checks (cleartool describe and, if need be, cleartool protect -chmod)
Note in both instances the presence of '##': it is to reference the element folder 'CC Training' (instead of the version).
start the Jenkins service as respective users
by using services.msc in run command

Visual C++ build error: Failed to register output

So I have this project I'm working on, and every time I build, it builds then executes the program, and then finishes with a build error. Why does this happen? I can't seem to find in the project properties where it would execute the file on the build.
It is kind of annoying, and it also ends up spawning an error. Here's an excerpt from the output
2>Link:
2> Generating code
2>c:\users\d0c\desktop\jlrria.lottery.repo\trunc\hash\hl_hashwrapper.h(277): warning C4706: assignment within conditional expression
2> Finished generating code
2> lottery-gui.vcxproj -> C:\Users\d0c\Desktop\jlrria.Lottery.repo\trunc\build\Release\lotteryslayer.exe
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(741,5): warning MSB3073: The command ""C:\Users\d0c\Desktop\jlrria.Lottery.repo\trunc\build\Release\lotteryslayer.exe" /RegServerRedirect" exited with code 2.
2> The previous error was converted to a warning because the task was called with ContinueOnError=true.
2> Build continuing because "ContinueOnError" on the task "Exec" is set to "true".<br>
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(744,5): error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.
2>
2>Build FAILED.
So I guess I'm looking for help with two things
First and most importantly: Why is it executing the build program
Second: Why am I getting this error?
thanks.
ALSO
There are no items in the post build, otherwise, the log above would say "post-build" :p
Start with Visual Studio with Administrator rights. You can do so by right clicking on VS shortcut and Select Run As Administrator. Or create a shortcut where you would enable Run As Admin.
Reason:
Look at the error:
error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.
Also, it seems to be a DLL/ActiveX control project. Look at: Linker->General->Register Output and set it to NO.
You are building an ATL project? Seems to be a bug in VS2010, http://social.msdn.microsoft.com/Forums/en/vcprerelease/thread/11f01ceb-52a4-438f-b7ef-727ce7a3e191 concerning ATL projects.