SQLite User Forum

version 3.52.0 (MINGW) shell link failure: undefined reference to WinMain
Login

version 3.52.0 (MINGW) shell link failure: undefined reference to WinMain

(1) By Mark Brand (mabrand) on 2026-03-07 11:48:53 [link] [source]

While upgrading sqlite3 to version 3.52 for MXE, I encountered this link failure:

x86_64-w64-mingw32.static-gcc -o sqlite3.exe /home/brand/dev/mxe/tmp-sqlite-x86_64-w64-mingw32.static/sqlite-autoconf-3520000/shell.c /home/brand/dev/mxe/tmp-sqlite-x86_64-w64-mingw32.static/sqlite-autoconf-3520000/sqlite3.c -Wl,-rpath,/home/brand/dev/mxe/usr/x86_64-w64-mingw32.static/lib -lz -I. -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_PERCENTILE -DSQLITE_ENABLE_RTREE -DSQLITE_HAVE_ZLIB=1 -DSQLITE_THREADSAFE=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_BYTECODE_VTAB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_OFFSET_SQL_FUNC -DSQLITE_ENABLE_PERCENTILE -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION -DSQLITE_HAVE_ZLIB=1 -DSQLITE_STRICT_SUBTYPE=1 -Os -DSQLITE_THREADSAFE=1

/home/brand/dev/mxe/usr/bin/x86_64-w64-mingw32.static-ld: /home/brand/dev/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/15.2.0/../../../../x86_64-w64-mingw32.static/lib/../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o): in function main': /home/brand/dev/mxe/tmp-gcc-x86_64-w64-mingw32.static/gcc-15.2.0.build_.crt/../gcc-15.2.0.build_/mingw-w64-v13.0.0/mingw-w64-crt/crt/crtexewin.c:66: undefined reference toWinMain'

I suspect the preprocessor logic in shell.c regarding wmain, defined under _WIN32, including MINGW. In version 3.51.2, wmain was not defined under MINGW. The following patch fixes the problem for me:

diff --git a/shell.c b/shell.c
index 1111111..2222222 100644
--- a/shell.c
+++ b/shell.c
@@ -36188,7 +36188,7 @@ static int vfstraceOut(const char *z, void *pArg){
** UTF8, then invoke the traditional main() entry point which is
** renamed using a #define to utf8_main() .
*/
-#if defined(_WIN32) && !defined(main)
+#if defined(_WIN32) && !defined(__MINGW32__) && !defined(main)
#  define main utf8_main                 /* Rename entry point to utf_main() */
int SQLITE_CDECL utf8_main(int,char**);  /* Forward declaration */
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){

(2) By Richard Hipp (drh) on 2026-03-07 12:03:06 in reply to 1 [source]

Please understand, we do not support MINGw32. If the build works with MINGW32, then great. If it breaks, then you get to keep both pieces.

That said, I did add your preprocessor patch to trunk. Please download the latest and let us know if that clears your problem.

(3) By Mark Brand (mabrand) on 2026-03-07 12:19:22 in reply to 2 [link] [source]

Thanks. sqlite-20260307120056-d95b9e7c17 builds perfectly.