Compiling code too quickly gives errors - c++

I have recently started coding with C++ and I have come across a little source of error which I think requires knowledge about computers that I don't have.
When I write a simple code (in Visual Studio Express 2013), let's say a "Hello World!" example, I Build and Start Without Debugging successfuly.
Then, when I edit my code to print the sum of two numbers for example, I get an error when I try to Build. I get this error:
Error 1 error LNK1168: cannot open c:\users\name\documents\visual
studio 2013\Projects\ConsoleApplication4\Debug\ConsoleApplication4.exe
for writing
But if I wait for a bit and then re-attempt to Build, everything is fine.
I have also noticed this when I use g++ in the standard cmd module; if I try to complile a code under the same name (for the .exe file) I get an Access Denied error, but if I wait a bit I am allowed to do it.
My instincts tell me that the computer still has the .exe file running for a bit after I execute it, and it is not allowing me to overwrite it.

It's because the process is still running and therefore the file is in use and write-locked. It takes Windows a few tempo beats to clean everything up after you've terminated.

Related

VS Code Error when compiling C++ Program: 'cmd' is not recognized as an internal or external command

I attempted to follow through on VS Code's method on making C++ code work on their editor. I did this successfully on my laptop but when I tried compiling it, I was met with the error:
* Executing task: C/C++: g++.exe build active file
Starting build...
C:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g "C:\Users\salty\Documents\Programming\C++ Scripts\myProgram\main.cpp" -o "C:\Users\salty\Documents\Programming\C++ Scripts\myProgram\main.exe"
'cmd' is not recognized as an internal or external command,
operable program or batch file.
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
* Terminal will be reused by tasks, press any key to close it.
This is the entire error message plus extra things in my editor.
If I try and copy and paste the command in the message into Windows Power Shell, it actually works (New .exe file appeared in the correct directory and runs without fault).
These are my environment variables for User, and these are my System variables.
I've tried uninstalling and re-installing and changing the paths around. I'm new to C++ programming and how compilers work in general, but I'm not sure why VS Studio says it doesn't recognize cmd among others it could've not recognized.
Why is it giving me this error?
Edit: I believe I didn't include a return 0; line in the program. Correcting this did not fix the issue.
I am not sure what I poked into place or if I just was too incompetent to realize something, however adding %SystemRoot%\system32 to my PSModulePath environment variables somehow fixed the issue, and since that action I have yet to replicate the compile error.
I don't know if adding that variable to my environments permanently fixed it or VS Studio needed a moment to process some things. Thanks anyways!

i don't know what is wrong with vs code in running cpp

i just started to code in cpp and nothing is working idk if i didn't install the gcc properly or what but i already set the path of the bin file idk why it refuses to run
the code:
#include<iostream>
int main()
{
std::cout<<"hello";
}
and the problem is that when I try to use the "code runner extension" it is not working so I just press f5 and then when I get the error messages which says at first "could not find the task file'c/c++:g++.exe build active file' " and I get three options 1:debug anyway
2:configure task
3:cancel
when I choose debug anyway I get this error here
Since you're on windows consider installing Visual Studio or CLion. They're more beginner friendly - VSCode can get tricky to run c++ on windows. Either way, looks like you're trying to run your project without building it first. There should be a build option right next to the run option. Try building it, then running. The build is what compiles and creates the project.exe file, which is what the compiler is saying isn't there.
The referenced IDE's always auto-build on run, so there's that
If you're familiar with using the command line, these commands will do what you want, assuming the .cpp file is in your current directory.
g++ <FILENAME>
./a.out
There are wonderful flags you can add to the first command (the compiling command) like -Wall, -Wextra, -o, and many more. But, since it seems like you're just starting out, there's no need to worry about those!
If you're not familiar with the command line, I would encourage you to become familiar! It is an extremely powerful tool for a programmer. Here is a YouTube video that talks about it.

invalid board header windows

I am trying to process a binary file generated by a PSI DRS4 for work. I tried this using a C++ code given in the src folder of the software used to run the board.
A friend of mine compiled and executed this code on his linux computer just fine. I wanted to adapt this code to windows. I went through the compilation step pretty easily but then when I try to execute it, it just crashes...
After some further investigation, what I understand is that the header(s) cannot be read properly (probably leading to the crash when they're supposed to be used later in the code)
I thus tried to read the file with HexEditor Neo and here is what I get: screenshot binary file Hexeditor
As you see the part after EHEADER becomes unreadable... Is it normal? Has anyone faced this situation before ?

Error: not.exe has stopped working - When trying to build LLVM

I am trying to build LLVM on windows, and everytime I do so I get to a certain point and then recieve an error that says "not.exe has stopped working" It pops up on the desktop about 15 times.
I am not sure what is going on, but when I check the error in Visual Studio I receive this:
Error 4 error : Couldn't execute program 'C:/Users/Cyborg/Documents/Developer'The process cannot access the file because it is being used by another process. C:\Users\Joe\Documents\Dev\llvm\test\CUSTOMBUILD check-llvm
I receive this error 5-7 times depending on how fast I click the error that pops up on the desktop. So clearly this issue is happening because of that.
The fault module is: MSVCR100.dll
Does anyone know why this is happening?
I don't know why you're getting the error since I don't build or use LLVM on Windows. Since no one else has chimed in, I'll try to give a hint or two.
"not.exe" (or "not" under Linux) is a little LLVM helper program used when running the lit based regressions tests. It is used to execute a program and return a good exit status if the program fails and a bad exit status if the program doesn't fail.
I'm guessing that "CUSTOMBUILD check-llvm" (what ever that is) is attempting to run the regression tests and your getting your mysterious error as a result whenevr "not" is used.
I hope that helps.

DOS-reported error: Bad file number

I have a batch file that tries to compile a static library using Borland C++ Builder 6.0
It is called from Borland make (makefile created with bpr2mak) which is called from a .bat file (used to compile the whole project with Visual Studio and some Borland C++ Builder legacy projects), which is called from a bash shell script running inside Cygwin.
When I run the .bat file directly from a Cygwin shell, it runs OK, but when its being run from a Program calling cygwin with Boost::Process::launcher I'm getting this error:
C:\ARQUIV~1\Borland\CBUILD~1\Bin\..\BIN\TLib /u bclibs.lib #MAKE0000.###
DOS-reported error: Bad file number
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
opening 'MAKE0000.###'
** error 1 ** deleting bclibs.lib
It's a complicated scenario, but this Program which calls cygwin is run whenever we need to build our software package which needs to be build for various Linux distos and Windows 32 and 64-bit.
Note: It's the only Borland Project failing, the other compile just fine (it's the only static library using borland also, so it can be some problem with the TLib tool.
The problem was that TLib does not like to have his output redirected (seen here) without having an input pipe as well. Solved by creating an input pipe to in the Boost::Process::launcher using set_stdin_behavior
I'm just guessing here, but this may have to do with long filenames and/or spaces in paths.
1) Modify your makefile so it would save current environment to a file, immediately before executing the failing command (set > d:\env.txt & echo CD=%CD% >> d:\env.txt). Then run it both ways (directly and via program) and compare the environments of good run and bad run.
2) Using filemon from Sysinternals, capture logs of disk access in both cases (these logs are going to be huge, though you can uncheck everything except Open in the filter to reduce the size). Again, compare and check for clues...
3) Try instaling everything involved to paths conforming to 8.3 scheme.
This error is not related to C++ itself. It happens when your build script opens too much files (more than defined in DOS command processor environment). To resolve this issue try to set value of files variable to 253. For Windows XP this variable defined in the file %WINDIR%\system32\config.nt.
files=253
Seems it is known bug in Borland C++ tools. Here is description and possible workaround for this issue:
Problem: Some static Lib projects will
not link correctly when compiled. You might see something
like this :
J:\Borland\CBUILD~1\bin\..\BIN\TLib /u debug\jpegD.lib #MAKE0000.###
DOS-reported error: Bad file number
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
opening 'MAKE0000.###'
** error 1 ** deleting debug\jpegD.lib
MAKE failed, returned : 1
Workaround : In some cases (where the "Bad file number" error is seen) it may be possible to work around this by specifying -tDEFLIB.BMK in the BPR2MAKE Options field, and Turning off the "Capture Make Output" option.
I have not tested it, but I hope that helps.