Page 1 of 1

wxMSW-3.1.3_gcc810_Dev can not static link?

Posted: Wed Feb 05, 2020 3:17 am
by kankouhin
create a wx sample and compile with:

mingw64bit can static link any library to exe, but with mingw32bit, it seems can not static link the librarys, after compiled ,the exe alse need
dll files within same folder. ex. wxbase313u_gcc810.dll, wxmsw313u_core_gcc810.dll and libgcc_s_sjlj-1.dll

How to static link librarys with mingw32bit?

Code: Select all

g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -Wall -O2 -IC:\wxWidgets-3.1.3\include -IC:\wxWidgets-3.1.3\lib\gcc810_x64_dll\mswu -c C:\wx\wxApp.cpp -o obj\Release\wxApp.o
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -Wall -O2 -IC:\wxWidgets-3.1.3\include -IC:\wxWidgets-3.1.3\lib\gcc810_x64_dll\mswu -c C:\wx\wxMain.cpp -o obj\Release\wxMain.o
g++.exe -LC:\wxWidgets-3.1.3\lib\gcc810_x64_dll -o bin\wx.exe  obj\Release\wxApp.o obj\Release\wxMain.o obj\Release\resource.res -s -static-libstdc++ -static-libgcc -static -mthreads  -lwxmsw31u_core -lwxbase31u -lwxpng -lwxzlib -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -lshlwapi -lversion -mwindows

Re: wxMSW-3.1.3_gcc810_Dev can not static link?

Posted: Wed Feb 05, 2020 7:18 am
by PB
Based on wxWidgets library folder name, you are linking the DLLs:
C:\wxWidgets-3.1.3\lib\gcc810_x64_dll\mswu

The static build should be in:
C:\wxWidgets-3.1.3\lib\gcc810_x64_lib\mswu
That assumes you are building wxWidgets by yourself, the wxWidgets pre-built binaries are dynamic linking only.

Obviously, if you do not want to depend on any DLLs, both wxWidgets and your program need to link to the compiler runtime libraries (CRT...) statically, e.g. wxWidgets are built with

Code: Select all

mingw32-make -f makefile.gcc BUILD=release  CXXFLAGS="-std=c++17 -static"

Re: wxMSW-3.1.3_gcc810_Dev can not static link?

Posted: Wed Feb 05, 2020 2:38 pm
by ONEEYEMAN
Hi,
To the OP - you should compile wxWidgets without "SHARED" option.
And of course use the same toolchain for both library and your own application.

Thank you.