I am working on learning the windows API and am using mingw as my compiler with Code::Blocks as my IDE. I have run into an issue with using the wWinMain function. I used the program located here link text. It compiles fine on VSC++ 2008 express but when using mingw i get the "undefined reference to WinMain@16" error. I have figured out what the problem is (i think). By replacing the wWinMain with just Winmain and the String pointer PWSTR with LPSTR it compiles perfectly. My question is, how can i fix this, and if not, is not using Unicode that big of a deal.
Thanks.
Mingw-w64 is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems. It has forked it in 2007 in order to provide support for 64 bits and new APIs. It has since then gained widespread use and distribution.
mingw.org has been outdated for years.
MinGW is "Minimalist GNU for Windows", The GNU toolchain is a set of apps that helps with building applications (and more). In that toolchain there is the GNU compiler collection GCC. The c++ compiler within that collection is g++.
Use MinGW with Visual Studio. It has been possible to use GCC based compilers with Visual Studio projects for some time already, but many cross-platform projects that build with MinGW on Windows are not organized into Solution and Visual C++ project files.
Code::Block is usually setup with MinGW, it will compile wWinMain but it gives link error because it doesn't recognize wWinMain as the entry point, it is still looking for WinMain entry point. You can just use the first version of WinMain, then use GetCommandLineW () for Unicode command line.
Newer Mingw versions also support -municode linker option switching to alternate startup code allowing to use wWinMain instead of WinMain (or wmain instead of main ). Add it to your command line, linker options in IDE or makefile. Show activity on this post.
Home Radio Audio Computing Software Gaming Food & Drink Contact News Facebook Introduction MinGW is a native Win32 port of the open source GNU Compiler Collection, and can be used to write applications targeting Windows in languages such a C and C++ (see the MinGW web sitefor further details of the supported programming languages).
However, the MinGW CRT startup library does not support wWinMain, so you’ll have to stick with the standard “WinMain” and use “GetCommandLine ()” if you need to access command line arguments. In this specific case, you can use WinMain instead.
For old versions of MinGW, you can use a wrapper:
mingw-unicode-main:
https://github.com/coderforlife/mingw-unicode-main/
Simple wrappers to add wmain and wWinMain support in MinGW
These wrappers allow for use of wmain / wWinMain in MinGW seamlessly with Unicode (WCHAR), regular (CHAR), or the ability to choose (TCHAR).
The instructions for using them are in the files. Also take a look at other programs that use them.
For new versions of MinGW, you should use the -municode
option, like it says in the mingw-unicode-main readme:
Note: This should no longer be used as MinGW now has a built-in solution. Add -municode to the command line (and possibly extern "C" to the wmain function).
The -municode
option works with MinGW-w64. In 2012-07, when I tried MinGW, it did not have the -municode
option.
Here is how to install MinGW-w64:
Target Win32:
Home > Toolchains targetting Win32 > Personal Builds > rubenvb > gcc-4.7-release:
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.7-release/
On Windows, you want "i686-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z".
Extract folder to the root of your drive.
Rename the "mingw32" folder to "MinGW-32".
Target Win64:
Home > Toolchains targetting Win64 > Personal Builds > rubenvb > gcc-4.7-release:
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/gcc-4.7-release/
On Windows, you want "x86_64-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z".
Extract folder to the root of your drive.
Rename the "mingw64" folder to "MinGW-64".
Unicode-related questions:
Use the plain (non unicode) WinMain
function, and then get your unicode command line using GetCommandLineW
. MinGW doesn't know about wWinMain
.
You are probably going to find working on MinGW difficult; last time I used it it did not support most of the wchar_t
components of the C++ standard library (i.e. std::wifstream
, std::wstring
, etc) which made interfacing with Unicode Windows bits difficult.
Do you have anything against MSVC?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With