I am working with code blocks using MinGW, and I have a coding project I’ve been working on for some time. The project I’ve been using has been console application, and the debug functions I have rely on printing to the console.
However, recently, I’ve tried to implement windows ‘GetOpenFileName()’ function to pull up an open file box so it’d be a lot easier for users to open files with. However, when using a project in console application with the headers included, the MinGW compiler acts like it can’t find the function. I found however changing the project to win32 GUI allows the compiler to find the function (I don’t entirely understand why but that’s just me).
The problem is thus: I tried to output debug information to console, but of course now the application is win32 GUI, the console doesn’t display and thus I cannot see the debug information, and I can’t switch it back to console application or the windows open file box code won’t compile. How do I both display the console and still allow the project to correctly compile the windows GUI code?
I cannot alter the debug functions or use different ones because they are written into all of the classes to assist with back-tracing errors and there are at least 43 files, most of which use the debug functionality.
And so the problem appears not to be caused by a project type, but a setting/compiler option. The compiler can find the function declaration just fine, but the linker now complains because it can’t find the definition.
In order to remedy this, you need to link to the correct library (which, as stated in the MSDN documentation, is
comdlg32.lib).In CodeBlocks, you can do this by:
Your project will now link to that library when building. If you want all programs, project or not, to link to that library, you can replace step 1 with the following step instead:
The rest is the same from there, but on a global basis.
For what it’s worth, if you’re using raw command line building, you can add the
-lcomdlg32option to produce the same effect.