News
Homebrew: wxWidgets static linking
by admin on May.01, 2022, under News
When building applications on macOS using wxWidgets the libraries are usually linked dynamically which makes the target executable a lot smaller. The downside, however, is that wxWidgets must be installed manually on any system our application is being deployed to (otherwise the application will crash due to missing symbols).
Compiling wxwidgets for static linkin
We’ll now tell Homebrew to compile for static linking.
brew edit wxwidgets
Scroll down to the part reading
def install
args = [
"--prefix=#{prefix}",
"--enable-clipboard",
"--enable-controls",
"--enable-dataviewctrl",
"--enable-display",
"--enable-dnd",
"--enable-graphics_ctx",
"--enable-std_string",
"--enable-svg",
"--enable-unicode",
"--enable-webviewwebkit",
"--with-expat",
"--with-libjpeg",
"--with-libpng",
"--with-libtiff",
"--with-opengl",
"--with-zlib",
"--disable-precomp-headers",
# This is the default option, but be explicit
"--disable-monolithic",
]
Append the following line to the end of this instruction:
"--disable-shared",
Now reinstall wxwidgets but add the build-from-source flag:
brew reinstall –build-from-source wxwidgets
If we build an application now the binary size will be much larger (typically several megabytes) but the application will be portable at the same time.