Recompiling code while program execution - c++

If I have a series of C/C++ programs that I need to build using Make , would it mess up the code run if I made changes to the code and recompiled while the program is executing an executable? Or is all the information preloaded in the executable before runtime?
Thanks.

This depends entirely on whatever operating system you're using.
Linux is perfectly happy continuing to execute a program whose binary has been removed, and replaced with a new binary.
It is my understanding that Microsoft Windows is, on the other hand, rather grumpy in the same situation, and won't be happy if something like this is attempted.

If I am understanding correctly, you can edit the code while you run the program and the program will not change while you run it.

Related

Compilation time between compiler and exe

After testing my program with big chunks of data I noticed that when I run my program on my compiler(Codeblocks) it runs slower than when I click the exe in my folder. Is that true?
Also when I click the exe it doesn't tell me the time it took to compile how can I see the time then?
When you run your application on in the IDE, it most often includes some other things for debugging purposes. In visual studio, it attaches a debugger and that takes up quite some performance.
When you directly run the executable, such debuggers wont get attached, thus improving the speed.
Another way to improve your executable performance is through compiler optimizations. You can read about them here: https://queue.acm.org/detail.cfm?id=3372264
Also when I click the exe it doesn't tell me the time it took to compile how can I see the time then?
What the compiler does is, it converts your source code into executables/ libraries. Basically if you run the compiler through your source code once, you don't need to do it again and again (which is what interpreted languages do).

Release version of program built in VS2015 with Qt runs then closes without errors?

I'm trying to build a release version of my chess engine that was built in the Qt environment and recently ported over to the visual studio 2015 environment. Everything runs fine in debug, and using this post here I was able to use windeployqt.exe to get dependencies that were giving error messages.
But now when I run it, it shows up in the process explorer for about 3-4 seconds then disappears. It's not throwing any errors so I'm not sure what's wrong. It could be it needs a dependency that I haven't copied yet? There's nothing that I know of that would cause it to run and quit, it never does that during debug.
Any tips or direction as to where to look for an answer would be appreciated! Thanks.
As trivial as it may sound, welcome to C++! You're programming in a very low level language that errors may some times crash your program with no apparent erros. This is not Java or Python or some high-level language where everything is done for you. In other words, if you mess up, you probably could get weird crashes like you're having.
There are many things you can do:
Delete all your compiled files and rebuild them from scratch. Linking issues with legacy code often cause what you're describing
If you added a list of libraries to link to (other than Qt), make sure that you need every library of them. Create a new "Hello world" program and link to them, and see if you'll get the same crash.
If it's not a linking issues, you're most likely having an access violation (or segfault).
Run the program in debug mode, and see if you get any information about the error.
The last resort is the low-level, stupid, binary search couting method. Basically you print a message in various places in your program, and see at which message the propgram will stop. The reason I call it "binary search", is because if have N places to test, with a binary testing approach you only need about log(N) compiles to find the problem, which is not a lot, but will cost you some time to recompile the program. In other words: Keep printing messages until you see where they stop appearing, and then blame that line.
Good luck.

Linking error in vc++

I am very new to VC++ and I am running the program on VC++ for the first time.
I strictly followed the instructions given in Microsoft Programming Visual C++ book and created one project as instructions given.
About the ex03a.exe:
I saw in the path "...\Ex03a\Debug\" and in that no file exists such as ex03a.exe.
I tested my vc++ by executing a simple 'Test.cpp' file. I was able to run the simple c++ program and I got the output. And Test.exe is there in '\Test\Debug\Test.exe'
My Question:
How could I get rid off the error.
Almost always when VS says it isn't able to open a file, it's about opening it for writing.
And almost always this doesn't work because the file is locked.
And almost always this is because the file is an executable that is currently running :-)
This is a specialty of Windows - an exe is not simply loaded, it's locked for all of it's run time. This is probably due to the fact that exe files (actually called portable executables, for whatever reason) contain not only code, but usually also an arbitrary number of resources (like images, etc.), and changing the file on the fly would make the aplication crash hard when it attempts to read one of those resources at run time.
Therefore, I suggest looking for a way to exit / close / terminate the application, so it isn't running any longer, so the file is not locked anymore, so in this case the linker can do its work.
The error message, btw., isn't that intuitive from my point of view - this problem being SO standard, it could at least attempt to tell you anything about this possible source of the problem - afaik, this hasn't been improved until now, probably because most developers have seen this before, found out why it happened, and therefore do not have any more problems with it.
I see that in that screenshot, that you are running multiple versions of VC6.
Now You get that error if you run the newly compiled exe of that program without shutting down the previous compiled exe.
VC tries to overrwrite the exe that is currenty running but encounters that exact error.
Always close the program when you are done.

Generate executable file at runtime - C++ / Visual C++

Maybe you can help me with a question I have, related to C++ language:
Is it possible or, is there a way to generate an executable file at runtime of a C++ Windows application?
To illustrate you why I'm asking this, I will detail the scenario that I'm thinking right now:
I have a C++ Windows Application that is more like an editor, where the user inputs some data and make some configurations, so when everything is done, the user clicks the "Run" button and this editor based on the user input data and configurations, creates some C++ or C# code files, compiles them and generates an executable file that the user can simply use without having to enter any line of code by himself.
Is it possible? Please can you give me a clue of how to do my search or where to find some help?
Of course it is possible, the compiler itself is likely a program that fulfils this requirement.
If you want to do it without just invoking a compiler though (and thus generate source code to feed it), you need to learn quite a bit about the machine language and executable file format of your platform.
You could simply make a call from your application to an external compiler, make the compiler build your executable and if the compilation is successful you could run the resulting executable. You can even capture the output of the compiler in your application.

Quick Question: Why do VC++ compiled exe's stop working if I change their names?

I'm working on a command prompt roguelike in VisualC++ 2008, and everything compiles all fine and dandy, but there's one glaring issue that I have with it.
Why is it that if I change the name of the exe, the program fails completely? I don't think that's supposed to happen with most programs
It's most likely because of the manifest file - you'll either need to rename the manifest file as well or embed it into the exe, see http://support.microsoft.com/kb/944276
It doesn't happen unless the program itself is designed to check its own exe's name and behave differently accordingly. You need to post some code.