-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix meson builds with msvc to make them truly static. #113
base: master
Are you sure you want to change the base?
Conversation
Similar to mingw-w64 we need special flags to compile the CRT in statically on static build with msvc. Otherwise users need to install the redistributeable package matching the compiler used for building, making the build not full stand alone. See: https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
if libui_mode == 'shared' | ||
if libui_is_debug | ||
libui_project_compile_args += ['/MDd'] | ||
else | ||
libui_project_compile_args += ['/MD'] | ||
endif | ||
elif libui_mode == 'static' | ||
if libui_is_debug | ||
libui_project_compile_args += ['/MTd'] | ||
else | ||
libui_project_compile_args += ['/MT'] | ||
endif | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These options are all hooked up in Meson as -Db_vscrt=
:
- none
- md
- mdd
- mt
- mtd
- from_buildtype
- static_from_buildtype
Specifically, what you're implementing here is identical to setting either from_buildtype
(if libui_mode == 'shared') or static_from_buildtype
(if libui_mode == 'static').
It's possible to set this in the project default_options, matching 'default_library=shared'
. People overriding that could just override both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, what you're implementing here is identical to setting either
from_buildtype
(if libui_mode == 'shared') orstatic_from_buildtype
(if libui_mode == 'static').
Yeah, I did see that config option. Sadly I did not find a way to override the default options depending on build type. I would want it to automatically use fom_buildtype
for shared
and static_from_buildtype
for static
. I would expect from_buildtype
to actually do that.
It's possible to set this in the project default_options, matching
'default_library=shared'
. People overriding that could just override both.
This would require the user to pass another parameter -Db_vscrt=
. I don't find this very user friendly. This is why I reimplemented the functionality. We are already doing the same for mingw builds anyways.
I am unsure why all those extra flags are needed in the first place. It is very unintuitive to me, why static ends up not being static. Not sure if these are ancient compiler/linker artifacts or if there is/was a good reason. For producing standalone binaries this is a nightmare though.
Similar to mingw-w64 we need special flags to compile the CRT in statically on static build with msvc.
Otherwise users need to install the redistributeable package matching the compiler used for building, making the build not fully stand alone.
I hope this fixes #67. For me this patch definitely fixes the
vcruntime140.dll
error and I am able to run the resulting executables fully stand alone. I am unsure aboutmsvcp140.dll
as I have never seen that one before.See:
https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
We might still want to add a note in the README.md though, I guess the corresponding redistributeable package is still needed for dynamic builds.