How do I use the wmain() entry point in Code::Blocks?
Asked Answered
A

3

9

I did a fresh install of Code::Blocks (I installed the one for Windows 7 which comes with GCC compiler (codeblocks-10.05mingw-setup.exe)). Then I tried to compile this very simple code:

int wmain(int argc, wchar_t* argv[])
{
    return 0;
}

I got this error message:

c:\development\ide\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1......\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16'| ||=== Build finished: 1 errors, 0 warnings ===|

When I try to run my code with a main() entry, it runs as expected without any errors or warnings. How can I use wmain() in my code? What modifications do I have to do?

Applicant answered 7/6, 2012 at 13:9 Comment(0)
P
3

Mingw does not fully support unicode. There is a wrapper available if you feel like trying it out. https://github.com/coderforlife/mingw-unicode-main

Pleach answered 17/7, 2012 at 7:47 Comment(0)
S
9

The latest solution is to use the -municode option instead of the mingw-unicode-main wrapper.

For details, see:

Simoom answered 29/7, 2012 at 8:26 Comment(4)
mingw32-gcc-4.8.1.exe: error: unrecognized command line option '-municode'Ardeha
Note: -municode must be added to the linker settings.Exerciser
I get the same error with the latest Code::Blocks (16.01) when adding -municode in the linker settings (linker is mingw32-g++.exe, and the MinGW directory also contains a mingw32-gcc-4.9.2.exe (which doesn't recognize the option either), but there's no mingw32-g++-4.9.2.exe)Dipsomaniac
@Medinoc: What nobody has bothered to tell us since 2012 is that there are two different compilers using the same name “MinGW”: TDM-GCC (integrated with Code::Blocks) and MinGW-W64 (further split into i686 and x86_64 variants). Confusingly, the latter is not a 64-bit version of the former. It’s just deceptive naming. Both are both 32 and 64-bit. And only the linker of the latter has the option -municode. Wasted a year of life – because people share advanced knowledge without basic knowledge.Qualified
P
3

Mingw does not fully support unicode. There is a wrapper available if you feel like trying it out. https://github.com/coderforlife/mingw-unicode-main

Pleach answered 17/7, 2012 at 7:47 Comment(0)
F
0

Well mingw doesn't support wmain. And why would they. wide characters is a Microsoft Windows specific thing. On Windows You can use GetCommandLineW and CommandLineToArgV. On Linux I understand that Linux doesn't do encoding transformations on the command line arguments. And you can manually convert to UTF16LE by checking the current locale.

Fettling answered 29/9, 2023 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.