8

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?

7vujy0f0hy
  • 8,741
  • 1
  • 28
  • 33
hkBattousai
  • 10,583
  • 18
  • 76
  • 124

2 Answers2

9

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

For details, see:

Community
  • 1
  • 1
XP1
  • 6,910
  • 8
  • 54
  • 61
  • `mingw32-gcc-4.8.1.exe: error: unrecognized command line option '-municode'` – rr- Feb 03 '15 at 19:06
  • 2
    Note: `-municode` must be added to the *linker settings*. – Marc.2377 Oct 31 '16 at 05:29
  • 1
    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) – Medinoc Nov 07 '16 at 16:14
  • 3
    @Medinoc: What nobody has bothered to tell us since 2012 is that there are two different compilers using the same name “MinGW”: [TDM-GCC](http://tdm-gcc.tdragon.net/) (integrated with Code::Blocks) and [MinGW-W64](https://mingw-w64.org/) (further split into [i686 and x86_64](https://unix.stackexchange.com/q/158244) 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. – 7vujy0f0hy Dec 21 '18 at 01:02
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

Arnestig
  • 2,285
  • 18
  • 30