Permission Denied building CPP file in Visual Studio Code - visual-studio-code

When I run the below given code on Visual Studio Code, first Building it, but it shows:
> Executing task: g++ -g main.cpp <
d:/software/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file a.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\Program Files\Git\bin\bash.exe '-c', 'g++ -g main.cpp'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
I have Bitdefender Antivirus on the system. It showed an error describing "Infected File Detected", it detected a.exe file and after that I removed it from quaratine and deleted the file from there in the Bitdefender software but now I am not able to run cpp file.
#include <iostream>
using namespace std;
class Aclass
{
public:
int x = 0, y = 0;
Aclass() { cout << "constructor of Aclass" << endl; }
}
int main () {
Aclass b;
}
I tried some solutions from stack and other forums but didn't work, though other forums there is nothing much but on stack I found one with solution to turn ON "Application Experience", but unfortunately I cant find it on services.msc
Any help will be much appreciated. Thank You.

I was also facing this same problem. To solve it you should open Bitdefender, then go to Exclusions setting, select Add a folder, and then navigate to your MINGW folder installation. Note that you have to select the entire MINGW folder, and then save it. Restart your system and then Visual Studio Code will not show this error.

Related

clang makes recompile everithing at each build in cmake

Here is a small c++ code, adapted from the tutorial Step 1 of CMake :
// tutorial.cxx
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial tutorial.cxx)
I used the extension of vscode CmakeTools, and I noticed that every time I build the project, it recompiles everything, even if nothing was changed. After some investigations, I found that the configuration of the project is made by vscode using this command :
/usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/clang-10 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10 -H/home/user/Bureau/projet/step1 -B/home/user/Bureau/projet/step1/build -G "Unix Makefiles"
(and if I configure by hand in the terminal with this command, it has the same behavior).
I noticed that if I configure the build directory without the option -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10, there is no problem afterwards: if a make if nothing has been charged in source, it doesn't recompile.
I have actually 2 questions :
Why does the option CMAKE_CXX_COMPILER:FILEPATH induces such a behavior?
How to configure vscode so it doesn't use this option anymore?
EDIT :
I tried to configure the project with another compiler (in the list, vscode proposes Clang10, GCC 8.4.0 and GCC 9.3.0). With Clang all is recompiled at each time, but this is not the case if I take GCC.
This answers my second question: use another compiler.
But still, I wonder why does Clang recompile everything ?

C/C++ debugger failing to create and write to raise.c in WSL using VSCode

I am trying to develop in C on WSL(2) (using Ubuntu) for a university course but am having trouble using the built in debugger for C/C++ in VSCode (installed via the C/C++ extension.
For my testings, I am running this code:
#include <assert.h>
int main() {
assert(1==0);
return 0;
}
When running into the assert, the debugger errors and VSC displays the following message on the bottom right corner:
Unable to open 'raise.c': Unable to read file 'vscode-remote://wsl+ubuntu/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c').
I have tried every single tutorial, github issue and stackoverflow question's answer but nothing has worked.
I have reason to believe that this has to do with VSC not having some kind of permissions to write/create files because if I press on Create File (which is prompted in the message), It says:
Unable to write file 'vscode-remote://wsl+ubuntu/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c' (NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/build')
but, if I create the folder /build and chmod 777 it, it is able to create the file, but not write anything into it.
Does anyone have a method to solve this?
Also, what is raise.c and why do I need it anyways?
According to the GDB skip function:https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-FilesPuede add it to "SetupCommands" under "configurations" in Launch.json:
{
"description": "Skip glibc files",
"text": "-interpreter-exec console \"skip -gfi build/glibc-YYA7BZ/glibc-2.31//**/*\""
}
But no problem, add WSL + Ubuntu / or VSL + ubuntu, it will ignore the path, it does not solve the problem, which may be valid for other environments, but it is not valid if VSCode uses remote connection. According to article number 811:Disable "Unable to open file" during debugThe developers say that the "Skip" command is also looking online, currently (January 27, 2019) I do not know of any other way. But there are other solutions under this issue, no need to compile Glibc library:
Execute this:
$ sudo apt install glibc-source
$ cd /usr/src/glibc
$ sudo tar xvf glibc-2.31.tar.xz
The "2.31" should be changed to the actual version number Source, and can be seen through the "LS" command. Then add that in "settings" in Launch.json
"sourceFileMap": {
"/build/glibc-YYA7BZ": "/usr/src/glibc"
}
The "YYA7BZ" is changed to the GLIBC suffix appears in the error message. If this method is not valid, you can change the path to: c:/users//AppData/ / / /local packages canonicalGroupLimited.ubuntuonWindows_79RHKP1FNDGSC / /localstate / / rootfs usr/src/glibc, where 79RHKP1FNDGSC should change the folder name on your own system.
Now searching for terminal error information:
Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-p3q623bu.gbr" 1>"/tmp/Microsoft-MIEngine-Out-s4xm3p6g.lqk"
according to the error when executing: ends Call After launching an instance of 'std :: logic_error'This is caused by an empty pointer. One of the possible causes of this problem is that I forgot to add the necessary parameters to add a run program in the "Args" list in "Configurations" in Launch.json.
Source:https://programmerclick.com/article/54012533450/
See this procedure, similar error but in different environment.
https://stackoverflow.com/a/48287761/16842210
In my case, I used try{}catch{} to print the error and saw what was, had nothing to do with raise.c

File not found error on Visual Studio Code when clicking on problems window (using make, gcc and gcc problemMatcher)

I work on a project which uses "make and gcc" to compile all its modules. These modules are on their own folders and have their own Makefiles. A global Makefile calls them in order to compile the binary.
So now I am trying to use Visual Studio Code as my IDE. I have set up the compilation environment and it works well.
The only problem is whenever there is some warning/compilation, clicking on them doesn’t open the proper file. My working directory will be similar to the below shown simplified code.
D:\SO
|-- common
| |-- main.c
| `-- Makefile
`-- Makefile
From the tasks I will be calling the outside Makefile, which will call the Makefile inside common. And in the main.c, I have deliberately deleted stdio.h header file inclusion, which should show an implicit declaration error.
But when I click warnings on problem window, VS code throws an error showing the file is not found. VS Code tries to open "D:\SO\main.c", but the file is actually inside "D:\SO\common\main.c"
Outer Makefile
all:
(cd common && make )
Inner Makefile (inside common directory)
all:
gcc main.c
main.c
int main(int argc, char *argv[])
{
printf("Hello World");
return 0;
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "make",
"command": "make",
"type": "shell",
"problemMatcher": [
"$gcc"
]
}
]
}
I have tried to tweak the problemMatcher by giving different combinations for fileLocation parameter. But they don’t yield a proper result. So I haven't included it here.
I am using Visual Studio Code 1.14.2 on Windows 10 1607 x64 with a mingw-gcc.
This isn't an answer to your question, but I expect it would be a prerequisite to any solution that Microsoft or others could provide.
You have a bug in your nested Makefiles. You should never do this pattern in a Makefile:
cd somewhere; make target
The cd is unnecessary (see below), but the use of make directly is a problem. Such a pattern messes up the ability for one invocation of make to pass information to sub-makes. In particular, it messes up parallel make. It also invokes make with the current shell path, which might not be the make that was originally used. You should always use this pattern instead:
$(MAKE) -C somewhere target
The -C dir parameter tells make where to set its current working directory. And using $(MAKE) allows flags and parameters to be passed down.
Since this is the recommended nested-Makefile pattern, I would think that any parsing that vscode would do to determine the appropriate fileLocation would likely require it.

Eclipse Path to Include Directories not working for me (Windows 7-64, C++)

I installed GCC (4.8.1) this morning and Eclipse Kepler (SR2). My Hello World compiled and ran fine, so I'm moving toward my goal of writing a C++ app using Boost. I installed Boost to "C:\Program Files\boost\boost_1_55_0" and added this path to Project>Properties>C/C++ General>Paths and Symols>[tab]Includes>GNU C++. However, when I compile, the path isn't showing up in the g++ command line, so understandably, the header file isn't getting found.
15:55:24 **** Incremental Build of configuration Debug for project BoostApp ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\BoostApp.o" "..\\src\\BoostApp.cpp"
..\src\BoostApp.cpp:1:32: fatal error: boost/filesystem.hpp: No such file or directory
#include "boost/filesystem.hpp"
^
compilation terminated.
15:55:24 Build Finished (took 78ms)
I realize this is a newb question and spent a few hours searching around and finding mostly direction to set the path, which I've done. I've checked the install and the header file is there. I've also done my own command line compile adding "-I C:\Program Files\boost\boost_1_55_0" to the command line and GCC found the header file fine.
Not sure where I'm going wrong. As mentioned, it's a new install of GCC, Eclipse, and Boost, so maybe I went wrong somewhere during the install or maybe creating the project? Or just a newb question? Below is the app I'm compiling which I copied from rosettacode.com
#include "boost/filesystem.hpp"
#include "boost/regex.hpp"
#include <iostream>
using namespace boost::filesystem;
int main()
{
path current_dir("."); //
boost::regex pattern("a.*"); // list all files starting with a
for (recursive_directory_iterator iter(current_dir), end;
iter != end;
++iter)
{
std::string name = iter->path().filename().string();
if (regex_match(name, pattern))
std::cout << iter->path() << "\n";
}
}

Eclipse Indigo CDT: Function could not be resolved

This feels silly, but its been 2 days...somewhere after upgrading from Ubuntu 10.04 to 10.11 and from Eclipse Helios to Eclipse Indigo, I got stuck with the following problem:
Problem Description:
I'm trying to use a function in math.h called isinf(), but the problem also occurs with things like isnan(). The program compiles fine on the command line using make and fine in eclipse using build. But if I open the program file in eclipse it reports that it cannot reolve the isinf() function call. If I just insert the program contents into a new project and new source file, the error appears immediately. This problem did not occur under 11.04 with Eclipse Helios CDT
Questions:
Why are these errors only reported when the program file is opened and not on when the program is compiled; why are the errors not detected make is run from the command line? Is there a solution/workaround available?
Version Info
Linux Ubuntu 10.11 64-bit
Eclipse CDT Indigo, Service Release 1, Build id: 20110916-0149
(Also using Eclipse EE Indigo – if that makes a difference)
GNU Make 3.81
gcc 4.6.1-9Ubuntu3
To Duplicate:
Please find the two files you'll need to replicate below:
Step 0. Verify that everything is fine outside of Eclipse
Copy the attached source file and make file
create a directory e.g. Mkdir FunTest
Save the source file a 'Test.cpp' and the makefile as 'makefile'
Open a command prompt and navigate to the directory e.g. FunTest
Enter 'make'
Enter ./TestOut
Program responds “is not infinite”
Step 1. Create the project in Eclipse
Open Eclipse
Select File|New|MakeFile Project with Existing Code
Click Browse – navigate to the directory (FunTest) and click ok
Select 'Linux GCC' from the Toolchain selector
Click Finish
Step 2. Find the Error
Click Build All (Ctrl-B) – project builds without errors
Open the project in the project explorer to display the file in the directory
Double click on the file “Test.cpp”
Note the error icon next to line testing for infinity
Note the 2 error messages:
Semantic error: Function _isinff could not be resolved
Semantic error: Function _isinfl could not be resolved
Test.cpp:
include <math.h>
int main(int argc, char **argv)
{
int TestNum = 10;
if (isinf(TestNum) == 0)
printf("Not infinite\n");
return 0;
}
makefile:
# Specify the compiler
CC = g++
# Specify the compiler flags
CFLAGS += -c
# Specify the files making up the application
SOURCES = Test.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = TestOut
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $#
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $#
install:
#echo "Build complete!"
I have experienced similar problems of the CDT reporting errors even though the code compiled fine within Eclipse Indigo.
Project > Properties > Settings > Binary Parsers > "GNU Elf Parser"
helped in my case. I had the "Elf Parser" checked.
That looks like a problem that many others have had with eclipse CDT before. Sometimes shutting eclipse down and then starting it back up again is enough to help. If that isn't the case, take a look at what I have below:
Compilation ok, but eclipse content assist having problems
Check your includes: if you're using include<math.h> change it to include<cmath>. The same for stdio.h and stdlib.h, you should replace by cstdio and cstdlib. Another option may be change you project to a C project instead of a C++.
You are missing -lm option in your build preferences.
Project->Properties->Settings->Miscleanous->Other (linker) flags[]
For me, it was solved by adding a specific ‘Source Location’ folder, and removing the default. In Luna, it is under:
Project > Properties > C/C++ General > Paths and Symbols > Source
Location