Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
undefined reference to `WinMain@16'
voidclass:
Source:
#include <iostream>
int wmain(int argc, wchar_t *argv[], wchar_t *envp[])
{
std::cout << "Hello world!" << std::endl;
return 0;
}
Build log:
Compiling: main.cpp
Linking console executable: bin\Debug\echod.exe
C:\MinGW\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 10 seconds)
0 errors, 0 warnings
thomas:
MinGW presently does not support wmain (don't have any information on whether it might in the future).
I am not sure if wmain is canon, anyway. It smells very much like a home-brewn Microsoft thing (but I may of course be wrong). Nevertheless, I've seen it around a couple of times, and it is well-known for making trouble.
The "correct" way to solve this problem as you can find on the internet is to use the CRT function __wgetmainargs from inside a normal main function. That function is neither documented, nor is it declared in the headers, so you'll have to properly declare it yourself before using it.
Personally, I have never bothered to do that (I perceive this as a hack, and I'd rather just use main), so I can't tell you an exact recipe for that.
Michael:
Hello,
I have found this than can help (at least a bit):
http://search.microsoft.com/results.aspx?mkt=en-US&setlang=en-US&q=wmain
http://www.hardforum.com/showthread.php?t=973922&page=3&pp=20
--> especially: http://www.hardforum.com/showpost.php?p=1028709866&postcount=48
http://sourceforge.net/mailarchive/message.php?msg_id=5078083
Best wishes,
Michael
Vampyre_Dark:
wchar is a built in type?
If you just want a hello world, you don't need all that, a simple
int main(BLANK)
{
...
return 0;
}
will do if you won't be passing the program arguments.
thomas:
--- Quote from: Vampyre_Dark on June 20, 2006, 11:07:18 am ---wchar is a built in type?
--- End quote ---
No, but wchar_t is.
--- Quote from: Michael -----> especially: http://www.hardforum.com/showpost.php?p=1028709866&postcount=48
--- End quote ---
I still perceive this as a hack, as it uses Windows API to do something that should just work in an OS-agnostic way.
But at least, CommandLineToArgvW is documented and prototyped. So I guess you've really found the best way to do it there :)
That is... if one actually needs the commandline. Vampyre Dark's objection was not entirely wrong, if you don't use the commandline parameters anyway, then of course plain old int main() is sufficient.
Navigation
[0] Message Index
[#] Next page
Go to full version