Reputation: 21
I'm a total beginner in general, learning c++. I have a laptop that is given by my school (because my own broke) at which I'm using to do some simple c++ stuff. I'm using visual studio code with C/C++ extension added to detect c++ code and it has works. My problem is when I try to do anything that requires administrator rights, I cannot do that as I need to head to our school's IT department, which I can't do as they're closed for the moment. I can't compile anything and I can't find the cl.exe that is supposed to compile (idk if that's correct or not), so I resorted to downloading MinGW and use their compiler (gcc version 6.3), thing is I can't set/change/see global variables nor environment variables(from control panel) as they're locked behind admin rights. Is there a way to edit the tasks.json(and the other) file(s) so I can for example compile(including making executables)/run/debug, by pathing to the g++.exe file? I'm willing to copy the other files like the .dll's if needed. I just want to be able to use the functions in vscode. (Right now I don't know what I need to include in the question to make it easier to "try to help" me. If you need anything like program version and cmd outputs then I'll gladly put them in). Note: "A no, it's not possible" is acceptable as I'm able to use code::blocks. I just want to know if it's pausible.
Edit: So I know a way to compile/build an .cpp project purely on cmd and g++ by commands like cd and move e.t.c, but I can't figure out how to implement that in the tasks.json file as I'd like to automate it. I can't edit the "command:" path because it has to lead to g++.exe file but when I try to build/compile my cpp file like that then it says: ""g++ not recognised as an internal or external command".
Upvotes: 0
Views: 1009
Reputation: 21
So uh, I found a solution to setting an environment variable even with the "environment variable" in control panel being inaccessible with admin lock. I set the PATH by doing 'setx PATH "[path to g++ folder];%PATH%" ' and 'set PATH=[path to g++ folder];%PATH% ' (I found the info here https://www.opentechguides.com/how-to/article/windows-10/113/windows-10-set-path.html) and ran the build with ctrl+shift+b and it compiled fine. My tasks.json file is shown below if anyone's curious. I found how to write it form here: https://code.visualstudio.com/docs/cpp/config-mingw:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
],
"version": "2.0.0"
}
Upvotes: 0