Debugging my C++ application
I'd like to ask you for help. Today I returned to my music player application after some time and wanted to add some features. But when I wanted to scan music files it always crashed. I reverted all the changes I made and it still crashes.
The only message I get in the console is that the program finished unexpectedly. I tried to print out some debug messages to find out where exactly it crashes. I narrowed it down to this line.:
TagLib::FileRef fileRef(reinterpret_cast<const wchar_t *>(fileName.utf16()), true);
This is the line where I create a fileRef instance using the famous taglib library. This code has worked for years. If my application couldn't locate the .dll file, I think it would crash immediately. Not when trying to use it, right?
The last working binary version I have was compiled using Qt 5.6 , now I upgraded to Qt 5.7. Could there be a problem with compatibility?
How could I get some more information about the crash? I have no experience with debugging C++ applications. Until now I was always able to find the problem using qDebug() messages. I'm more familiar with Python which always gives me a helpful error message and tells me what went wrong and where. But my C++ program just crashes when calling the command mentioned above.
This code runs in a background thread, I don't know if it is important.
TagLib::FileRef fileRef(fileName.toUtf8().constData(), true);
Unfortunately this won't even compile. I now have an idea what might be the problem. I compiled the taglib.dll some time ago. So maybe it is now incompatible with Qt 5.7 built by newer GCC.
So I tried to compile TagLib using the MinGW binary which comes with Qt. I recompiled the library and replaced the old one with this. Now the application won't even start and right crashes. Again without any useful information about the crash.
Are you sure that the TagLib .dll can be found when your application starts ?
Yes, the library can be found. I think I would get an error about it and the application would not even start.
This is what I discovered so far:
- Qt 5.6 and TagLib compiled with GCC 4.9 - no problems
- Qt 5.7 and TagLib compiled with GCC 4.9 - random crashes when using the library
- Qt 5.7 and TagLib compiled with GCC 5.3 - immediate crash
The .dll files are in the same place, nothing is different, only the Qt version and GCC version used to compile TagLib. Is it possible that TagLib is not compatible with GCC 5.x? This is probably not the right place to ask this question.
But my original problem seems to be case by the incompatibility of GCC 4.9 compiled library with GCC 5.3 compiled Qt. And it can not be solved by recompiling the library with GCC 5.3. So for now I reverted back to Qt 5.6 where everything works as expected.
Did you enable C++11 when building TagLib for Qt 5.7 ?
No, I did not. However I don't know if it was enabled or not. I used CMake-gui and then mingw32-make from command line. How can i enable or disable C++ 11 in this toolchain?
See here for how to enable c++11 with cmake
I tried to enable C++11 when compiling TagLib but it still crashes with Qt 5.7 right after program start.
Can you run a simple application with only TagLib and not Qt code involved ?
So have you tried running it under a debugger ?
@SGaist Thank you for the tip. It helped me to solve the crash. The TagLib source contains also some examples so I built them too. When trying to run it, it complained about missing zlib1.dll. And that was also the problem in QtCreator. I compiled the LagLib library with ZLib support but I didn't copy the zlib1.dll to the build directory. Now with TagLib compiled using GCC 5.3 with C++ 11 enabled, my application works fine also with Qt 5.7.
@KeithS No, I did not. That was my original question, how should I use a debugger so I don't have to use my usual try-error approach. This problem is now solved but I would still appreciate some information source/guide where I could study how to use it.