Make produces sometimes broken executables
I noticed that make sometimes produces bad executables after applying small changes to cpp files. The generated program crashes sporadically at some points. The problem is reprodceable until I clean the build directory and make the executable again.
Is that a well-known issue or can I do something to fix it?
Difficult to say what's the problem. Try to create a simple test case, it can be useful to understand what is happenning and, if it's a Qt bug, this test will became an important part of a bugreport.
Are you using qmake? If your dependency tree is right, it shouldn't happen.
I've saw cases when adding Q_OBJECT macro after the first compiling produces some mistakes related with moc and metaobject methods. But it will not affect the binary since your code will not compile.
Can you reproduce this problem and write down the steps here?
Yes I use qmake and then make (through the qtcreator IDE). No, i cannot reproduce it, because that problem occurs only randomly. But it happend about 4 times this week. I will monitor it longer.
Are you sure you haven't messed up the stack in your program? Could you show us the backtrace?
I will need to find a way to reproduce the problem. Unfortunately (or happily) it did not happen sind I wrote this topic, and I compiled a lot since then.
One of the reasons for undetermined behavior of an application might be uninitialized variables. Try to check them in your source code. Some time ago I used valgrind for that, it gives an error if it bumps into uninitialized variable.
Thanks for your hint. I compared the current source with the old one where the problem occured several times and I think I found the problem cause. Under certain conditions, the application deleted a single object twice.
The problem occured again today. I am sure that the program does not mess up stack and there are no uninitilized variables anymore. The only thing that I changes was, that I placed a preprocessor directive around a debug logging statement, so it is only enabled when I compile the debug version.
After compilation, the program crashed repeatedly at the same point. I klicked on the rebuild link, which did not help. Then I inserted lots of additional debug messages to find the exact point because the debugger does not start properly (which is a well-known bug in the current release). But none of these new messages appeard, altough the program was obviously executing the related part of code.
So it was obvious that the make did not update the *.o file anymore. I selected the cleanup function in QT Creator, but some few files have been left in the build directory. After recompilation, the problem was still there. The I deleted the build directory manually, and voilla - problem was gone and the new debug messages are also visible now. The program does not crash anymore.
Could you paste the backtrace?
It is normal behaviour.
Whenever you make a change that requires the preprocessing of files, you need to rebuild at least that part of the source tree.
Always rebuild the complete source, or, split a big source tree up in managable parts.
Edit: to make this a little bit clearer:
Yes, the .cpp or .h file changed. It gets recompiled. However, it does not get preprocessed again automatically.
How can I create a backtrace an what is it good for? (Please remember that I cannot use the Debugger in QT Creator with my application, it is not able to start the application, so doing something on the command-line would be more helpful).