(VSC) Terminal Issues When Running Commands (C++) - c++

I'm a beginner when it comes to coding so I have very little knowledge of what is going on with this.
Please explain simply for me if possible.
c1xx: fatal error C1083: Cannot open source file: 'TripleX.cpp': No such file or directory
This is the type of error i'm getting when I try to find a directory with the default powershell being CMD.
Another problem I have is what my code opens when I try to run it. When I right click the file up in
open editors and click open in new terminal, when I do a cl command it actually works.
However, when I run it, the power shell switches to code, notepad, or visual studio 2019. I need help fixing this. (Btw none of the 3 listed applications actually run the code. They just open with the code inside).
I've tried switching what application VSC opens the code with.
I've tried moving the file around to see if cmd can reach the file.

Related

Visual Studio Code: path of files in CMake Tools tab is incorrect

I hope this is not a duplicate, as I have been searching the web for a while looking for solutions to my issue.
So, I am working in this C++ project from the lab I work at which works just fine in CLion and Visual Studio. However, I'm trying to run it in my local machine with Visual Studio Code and have installed the extensions C/C++ and CMake Tools by Microsoft, and CodeLLDB by Vadim Chugunov.
When I open the folder which contains the CMakeLists.txt file and locate it with the CMake extension, the project is detected and mounted just fine in the CMake tab. The project structure is there, and I can even build it. However, I am not able to access the files through the CMake tab (to edit them and insert breakpoints), as I get this error:
Unable to open 'main.cpp': Unable to read file
'/home/leonardo/Git/MPMc/MPMc/cmake/Git/MPMc/MPMc/MPM/main/main.cpp'
(Error: Unable to resolve non-existing file
'/home/leonardo/Git/MPMc/MPMc/cmake/Git/MPMc/MPMc/MPM/main/main.cpp').
I see it is reasonable that the program cannot read the file, as its address is looped within itself. So what I really wanted was to know how to avoid this behavior so VS Code could see the real address of the files and allow me to access them.
BTW, I am running a Manjaro 18 system and didn't have the same problem with the lab machine, which runs Debian 10.
Could you guys give me any tip as to what could be the solution to this issue? Is this a VS Code issue or a system issue?
Thanks!

VS Code C++ debugging

I try to debug my C++ programs but it shows me this error:
Could not find the task 'g++ build active file'.
I tried adding a configuration as Visual Studio Code says in its website, by choosing C/C++: (gdb) Attach, but nothing changes.
I struggled for days to setup a running and debugging environment for C++ in VS Code. Finally I found a way to solve the problem. Please follow the below steps
Prerequisites- Have Mingw32 installed on your PC.
Install C++ extension for VS code
Install Competitive programming helper extension for VS code. Something like
this will appear on the left panel.
Open your .cpp file and open the test runner by clicking on the highlighted are in the above image. Enter the inputs and click on the runall button in the above image you will be able to see the output.
For debugging :-
1.Click on the debug button in the below image . You would get an option stating “Run and Debug file”. Click on that.
It would create a launch.json file and task.json file. Delete the task.json file as we are using competitive programming helper extension for running our cpp files.
Below is the content of launch.json to setup the debugger environment
Paste the same exact configuration mentioned above in your launch.json file.
For the “miDebuggerPath”, please provide the location of the gcc.exe file inside mingw32 folder on your pc.
In the args key I have used "args": ["<", "${fileDirname}\input.txt",">", "${fileDirname}\output.txt"],
The above code is use to take input from input.txt file and write output to output.txt file while debugging for the easy input and output. Please create a input.txt and output.txt in the same folder where you have all your C++ files.
Add a breakpoint in your .cpp file and run the debugger by click on the green RUN button , your debugger would start and it would take all the input from input.txt and write the output in the output.txt after the debugging session ends.
Happy Coding.
Unfortunately, cannot add a comment, so I have to submit an "answer", which is merely a guess. Did you download "mingw64" with g++? Probably, you did not add mingw64/bin to your system path. Control panel -> Edit path -> Environment variables -> Path -> New.. (it is also in the tutorial link below)
To really make sure the things run, check this tutorial, by Microsoft: https://code.visualstudio.com/docs/cpp/config-mingw
Perhaps, uninstall your downloaded g++ and install this mingw64 repository. Quite helpful. I use it myself and for a quick debugging - works like clocks!

after build any window is opened c++

I did a disk partition to get Linux to be able to practise with c++ and it is impossible because I don't find the error I did install code blocks.
I tried to use the xterminal but it's a bit annoying just for practice!
Every time I try to run my program in codeblocks appears this message "Can't create output directory bin/Debug/" and I cant see my program... do I have to install anything else?
my program doesn't appear after build
I think you don't have permission to the directory to build.
Change the build or output directory from settings of CodeBlocks then try...

Eclipse C/C++ "Permission Denied" error

I'm using Eclipse Helios in Windows7 for C/C++ programming. I wrote a basic C++ code and tried to compile. The output is:
**** Incremental Build of configuration Release for project Programming Project **** Info: Internal Builder is used for build g++
-o "Programming Project.exe" "src\ch_3_excercises.o" c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe:
cannot open output file Programming Project.exe: Permission denied
collect2: ld returned 1 exit status
How can I fix this error?
All you have to do is go to project on the menu bar and then click clean project. Clean all of your projects and then it should work.
The same problem with me while editing my code.the easy way i used is ::::::::
press the red button(Terminate) before editing your code then run your code
it is tested and works
I know this is an old question, but it probably does that because you are interrupting the flow of your program, for instance using scanf(), and not actually giving the input it requires, so when you use the command Build the project, then eclipse is waiting a stream from your keyboard (for instance, maybe it's a different type of program, but follow me here).
Once you know than that is the problem, then you might wanna keep an eye in what is that you are not giving to the project and that it is expecting you to; and the way to stop this annoying error the next time you get it, is that in your console view you press the red button.
That will happen if the program is still running in another window. The .exe file stays open until the program finishes execution, and you can't delete a file while any processes have it open.
I don't use Eclipse for C/C++ development, and the problem almost can't happen with Code::Blocks, but this happens very often with Visual C++. Just close the other window and rebuild.
Check your quarantine folder of your antivirus. If you see the executable file, then add it to the Trust list or White list. Your problem should be solved.
It means the same .exe file is running in your system.
A program cannot be build when its already running.
So the simple and most obvious thing to do is:-
Open task manager
Find <yourfilename.exe> under processes
Right click and end task
This stops it from running in background.
So you can build your program anew and run.

Error in basic C++ program running in Netbeans IDE with Cygwin

I recently started learning C++ and I installed Netbeans IDE 6.9.1 and also the Cygwin compiler packages and configured them, and added Cygwin to my environment variable PATH like the instructions told me to.
I wrote a basic "Hello World" program and when I press Ctrl+F5 to "Debug Main Project" it seems to build fine but the black console/command prompt window flashes then disappears.
Then when I go to Run > Run Main Project, it builds and then a command prompt window pops up with the directory to "sh.exe" in its title.
I took a screenshot of the error message:
Does anyone know why this is happening and why I can't get the program to run properly even in debug?
Notice that in the screenshot I switched over to the MinGW tools because I thought maybe Cygwin was the problem, but the same error still occurs.
Any help would be greatly appreciated. Thank you.
"No such file or directory" in the error message is the key. When you run the project, it wants to access a file which is not there. Make sure that the paths are set up correctly.