Closed Bug 411826 Opened 17 years ago Closed 17 years ago

Mingw build error: undefined reference to `WinMain@16'

Categories

(Toolkit :: Startup and Profile System, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9beta4

People

(Reporter: martijn.martijn, Assigned: Mook)

References

(Blocks 1 open bug)

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

I'm getting this build error in my mingw debug build:
ADERS=1 -DHAVE_DIRENT_H=1 -DHAVE_GETOPT_H=1 -DHAVE_MEMORY_H=1 -DHAVE_UNISTD_H=1
-DHAVE_MALLOC_H=1 -DHAVE_LIBM=1 -DNO_X11=1 -DMMAP_MISSES_WRITES=1 -DHAVE_STRERRO
R=1 -DHAVE_SNPRINTF=1 -DHAVE_MEMMOVE=1 -DHAVE_RINT=1 -DVA_COPY=va_copy -DHAVE_VA
_COPY=1 -DMOZ_EMBEDDING_LEVEL_DEFAULT=1 -DMOZ_EMBEDDING_LEVEL_BASIC=1 -DMOZ_EMBE
DDING_LEVEL_MINIMAL=1 -DMOZ_PHOENIX=1 -DMOZ_BUILD_APP=browser -DMOZ_XUL_APP=1 -D
MOZ_DEFAULT_TOOLKIT=\"cairo-windows\" -DMOZ_THEBES=1 -DMOZ_CAIRO_GFX=1 -DMOZ_DIS
TRIBUTION_ID=\"org.mozilla\" -DOJI=1 -DIBMBIDI=1 -DMOZ_VIEW_SOURCE=1 -DMOZ_XPINS
TALL=1 -DMOZ_JSLOADER=1 -DNS_PRINTING=1 -DNS_PRINT_PREVIEW=1 -DMOZ_NO_XPCOM_OBSO
LETE=1 -DMOZ_XTF=1 -DMOZ_MATHML=1 -DMOZ_ENABLE_CANVAS=1 -DMOZ_SVG=1 -DMOZ_SVG_FO
REIGNOBJECT=1 -DMOZ_UPDATE_CHANNEL=default -DMOZ_PLACES=1 -DMOZ_FEEDS=1 -DMOZ_ST
ORAGE=1 -DMOZ_SAFE_BROWSING=1 -DMOZ_URL_CLASSIFIER=1 -DMOZ_LOGGING=1 -DHAVE___CX
A_DEMANGLE=1 -DMOZ_DEMANGLE_SYMBOLS=1 -DHAVE__UNWIND_BACKTRACE=1 -DMOZ_USER_DIR=
\"Mozilla\" -DHAVE_STDINT_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_UINT64_T=1 -DMOZ_XUL=1
-DMOZ_PROFILELOCKING=1 -DMOZ_RDF=1 -DMOZ_MORKREADER=1 -DMOZ_DLL_SUFFIX=\".dll\"
-DJS_THREADSAFE=1 -DMOZ_REFLOW_PERF=1 -DMOZ_REFLOW_PERF_DSP=1 -DMOZILLA_LOCALE_V
ERSION=\"1.9a1\" -DMOZILLA_REGION_VERSION=\"1.9a1\" -DMOZILLA_SKIN_VERSION=\"1.8
\"  -D_MOZILLA_CONFIG_H_ -DMOZILLA_CLIENT /cygdrive/c/mozilla/mozilla/browser/ap
p/nsBrowserApp.cpp
/usr/bin/perl /cygdrive/c/mozilla/mozilla/config/version_win.pl -QUIET 1 -DEPTH
../.. -TOPSRCDIR /cygdrive/c/mozilla/mozilla -BITS 32 -OBJDIR . -SRCDIR /cygdriv
e/c/mozilla/mozilla/browser/app -DISPNAME Minefield -DEBUG 1 -BINARY firefox.exe
 -RCINCLUDE /cygdrive/c/mozilla/mozilla/browser/app/splash.rc
Creating Resource file: module.res
/cygdrive/c/mozilla/mozilla/build/cygwin-wrapper windres -O coff --use-temp-file
 -DMOZ_PHOENIX --include-dir /cygdrive/c/mozilla/mozilla/browser/app -DAB_CD=en-
US -DAPP_VERSION="3.0b3pre" -DAPP_UA_NAME="Minefield" -DGRE_MILESTONE=1.9b3pre -
DGRE_BUILDID=2008011003 -DMOZILLA_INTERNAL_API -DOSTYPE=\"WINNT5.1\" -DOSARCH=WI
NNT -DFIREFOX_ICO=\"../../dist/branding/firefox.ico\" -DDOCUMENT_ICO=\"../../dis
t/branding/document.ico\" --include-dir /cygdrive/c/mozilla/mozilla/toolkit/xre
--include-dir ../../dist/include/xpcom --include-dir ../../dist/include/string -
-include-dir ../../dist/include/xulapp --include-dir ../../dist/include --includ
e-dir ../../dist/include --include-dir ../../dist/include/nspr -o module.res /cy
gdrive/c/mozilla/mozilla/_firefox/browser/app/module.rc
/cygdrive/c/mozilla/mozilla/build/cygwin-wrapper g++ -mno-cygwin -o firefox.exe
 -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Woverloaded-virtu
al -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-l
ong -pedantic -mms-bitfields -pipe  -DDEBUG -D_DEBUG -DDEBUG_mw -DTRACING -g  ns
BrowserApp.o ./module.res -mconsole           -L../../dist/bin -L../../dist/lib
 -lxul -L../../dist/lib -ljs3250 -L../../dist/lib -lxpcom -lxpcom_core -L../../d
ist/lib -lnspr4 -lplc4 -lplds4   -lm  -lgdi32 -lwinmm -lwsock32 -lcomctl32 -lcom
dlg32 -luuid -lshell32 -lole32 -loleaut32 -lversion -lwinspool -lusp10 -lmsimg32

c:/mozilla/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main
.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
make[5]: *** [firefox.exe] Error 1
make[5]: Leaving directory `/cygdrive/c/mozilla/mozilla/_firefox/browser/app'
make[4]: *** [libs] Error 2
make[4]: Leaving directory `/cygdrive/c/mozilla/mozilla/_firefox/browser'
make[3]: *** [libs_tier_app] Error 2
make[3]: Leaving directory `/cygdrive/c/mozilla/mozilla/_firefox'
make[2]: *** [tier_app] Error 2
make[2]: Leaving directory `/cygdrive/c/mozilla/mozilla/_firefox'
make[1]: *** [alldep] Error 2
make[1]: Leaving directory `/cygdrive/c/mozilla/mozilla/_firefox'
make: *** [alldep] Error 2

C:\mozilla\mozilla>


Removing this line:
#ifdef XP_WIN
// we want a wmain entry point
#include "nsWindowsWMain.cpp"
#endif
from nsBrowserApp.cpp fixes the build error for me.
Removing which line? You need to enter through wmain, not main. Whatever compiler/linker flags are necessary to make that happen should be used.
It looks as if mingw doesn't support wmain(); you could write a stub that uses GetCommandLineW and CommandLineToArgvW instead, though I guess it won't handle wildcards...
Attached patch Use CommandLineToArgvW (obsolete) (deleted) — Splinter Review
Note Firefox built with MSVC71 also doesn't handle wildcards anyway (it looks for http://www.*.txt/ instead of opening README.txt in the Firefox directory).

This builds, at least...
Attachment #301244 - Flags: review?(martijn.martijn)
Comment on attachment 301244 [details] [diff] [review]
Use CommandLineToArgvW

Hey Mook, thanks for coming up with a patch! This fixes indeed the mingw build error, but I'm really not suited for reviewing this.
Attachment #301244 - Flags: review?(martijn.martijn)
Comment on attachment 301244 [details] [diff] [review]
Use CommandLineToArgvW

Okay, bumping to bsmedberg instead... :)
Attachment #301244 - Flags: review?(benjamin)
Comment on attachment 301244 [details] [diff] [review]
Use CommandLineToArgvW

>Index: toolkit/xre/nsWindowsWMain.cpp

>+#ifdef __MINGW32__
>+
>+/* MingW currently does not implement a wide version of the
>+   startup routines.  Workaround is to implement something like
>+   it ourselves.  See bug 411826 */
>+
>+#include <shellapi.h>
>+
>+int wmain(int argc, WCHAR **argv);
>+
>+int main(int argc, char **argv)
>+{
>+  LPWSTR commandLine = GetCommandLineW();
>+  int argcw = 0;
>+  LPWSTR *argvw = CommandLineToArgvW(commandLine, &argcw);
>+  if (!argvw)
>+    return 127;
>+
>+  int result = wmain(argcw, argvw);
>+  GlobalFree(argvw);
>+  return result;
>+}
>+#endif /* __MINGW32__ */

According to http://msdn2.microsoft.com/en-us/library/bb776391.aspx you should be using LocalFree instead of GlobalFree, though I think they end up being the same thing. r=me with that change
Attachment #301244 - Flags: review?(benjamin) → review+
Attached patch Use LocalFree instead (deleted) — Splinter Review
carrying forward r+. cvs log seems to indicate no sr needed for the file?
Assignee: nobody → mook.moz+mozbz
Attachment #301244 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #302262 - Flags: review+
Keywords: checkin-needed
Oops, reed mentioned that there's no a+, so no checkin.  Sorry!
Keywords: checkin-needed
Comment on attachment 302262 [details] [diff] [review]
Use LocalFree instead

#ifdef __MINGW32__ only, so not going to show up in anything but tier-3 (err, I think that's where mingw/gcc is.  definitely not tier-1 though.)
Attachment #302262 - Flags: approval1.9?
Attachment #302262 - Flags: approval1.9? → approval1.9+
Keywords: checkin-needed
Checking in toolkit/xre/nsWindowsWMain.cpp;
/cvsroot/mozilla/toolkit/xre/nsWindowsWMain.cpp,v  <--  nsWindowsWMain.cpp
new revision: 1.5; previous revision: 1.4
done
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9beta4
This problem also occurs in toolkit/mozapps/update/src/updater/progressui_win.cpp via an include of progressui.h which has

#define NS_main wmain

Should I file a separate bug for this?
(In reply to comment #12)
> Should I file a separate bug for this?

Yes, please.
OK, filed Bug #416950
Component: XRE Startup → Startup and Profile System
QA Contact: xre.startup → startup
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: