问题
Problem: CLion doesn't output any console output for debugging purposes.
I'm using CLion with the MingW compiler and cmake. No matter whether I use:
std::cout << "Testing" << std::endl;
Or:
printf("Testing");
I don't see any console output.
Attempts at Resolution:
1: I've checked "Run", "Debug", "Terminal" and "Cmake". I've attempted to edit my configurations but "Debug" doesn't show up.
2: Next, I went to Settings->Build,Execution,Deployment->CMake to edit the Generation types. I added Debug and RelWithDebInfo and still to no avail.
3: I also attempted to add "-Debug" to Cmake, but I still have no output.
4: The closest thing I've received for debugging is using GDB to view variable values at break points. This only works in the "RelWithDebInfo" generation.
回答1:
Solution:
I ended up figuring out what the problem was.
I'm developing a Qt GUI application within CLion on Windows. You have to specify a console for console output to print onto.
Call this Console() function early in your main for a console prompt to open up. Now, whenever you run
QDebug() << <string>;
or
std::cout << <string> std::endl;
You'll see your debugging statements. Hope this helps somebody else out there with the same problem.
Code:
void Console()
{
AllocConsole();
FILE *pFileCon = NULL;
pFileCon = freopen("CONOUT$", "w", stdout);
COORD coordInfo;
coordInfo.X = 130;
coordInfo.Y = 9000;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coordInfo);
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),ENABLE_QUICK_EDIT_MODE| ENABLE_EXTENDED_FLAGS);
}
Source:
I found a solution here: [0] Console output in a Qt GUI app?
来源:https://stackoverflow.com/questions/41841036/how-do-i-configure-clion-standard-console-output