Saturday 22 September 2012

Mingw And The Mystery of the Missing Console

So, you create a new GUI project in Qt Creator and then decide, during development, to get some console output; say, you're testing some code you're not exactly sure how it will work, and you haven't even built a GUI yet, so it's easier to get some couts going.

Well, you may or may not comment out gui references in your QT variable, in you .pro file. But you better don't forget to add CONFIG += console. What happens if you don't? Well, let's assume you have something like this:

#include <iostream>
using std::cout;
using std::endl;

int main(int argc, char *argv[])
{
    cout << "start" << endl;
}

If you run it in the IDE, all is well. If you open a DOS window and run it from there, you get nothing. No error, no output, nothing. You may wonder if anything is going wrong before execution hits main(), so you fire gdb, set a breakpoint in main() and run it. It stops on your breakpoint, steps perfectly through you cout, but still nothing happens.

And, throughout all of this, not a single warning. It sets my eyes on fire with warnings if I have a variable that I'm not using (yet), but it doesn't seem to have the insight to tell me "You're using cout, but you didn't specify -subsystem,console; if you're expecting to see any output, boy, are you in for some Interesting Times".

Anway...

Testing on libssh2 + asio is still going on.

Also, I've just installed VS 2012 Express. I've already built libssh2 with it (and OpenSSL + zlib). It was easier building it with mingw, so there goes my theory that everything is easier to build on Windows if you have VC++.

1 comment: