mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.64k stars 1.64k forks source link

Make a fully statically linked .exe #1104

Open msink opened 7 years ago

msink commented 7 years ago

As you say in "Design rationale for the Wrap dependency system" - in windows most proramms are statically linked into one binary. So this should be а goal of this project.

But I don't see any portable way for this.

In mingw I can manually add "-static" to link_args, and it works. In msvc this required /MT runtime instead if /MD, but I don't see this option at all.

nirbheek commented 7 years ago

Do you want to switch the runtime on a per-target basis or on a per-project basis?

msink commented 7 years ago

In most cases per-project. Just want everything linked in one binary, without dependencies on non-default .dll-s

nirbheek commented 7 years ago

There is more fixing that needs to be done to make this work in all cases, for instance an option to prefer static libraries over shared libraries while searching for them with cc.find_library, but I think we can implement part of this by adding a new option called default_runtime with shared and static.

This is also relevant on desktop Linux and on embedded Linux if you want to use your own C++ STL. This is also necessary on iOS since it only allows static executables.

We need to also explore other options for implementing this by looking at the various use-cases that people will have.

jpakkane commented 7 years ago

In the mean time you can manually set buildtype to plain and add /MT yourself to compiler args.

msink commented 7 years ago

In the mean time I can just use mingw with -static flag :)

As of embedded linuxes - they usually use variants of gcc and maybe clang The only weird thing I saw was SHARED FLAT library format - https://blackfin.uclinux.org/doku.php?id=toolchain:creating_libraries "Each FLAT shared library needs to have a unique ID associated with it, and making sure each ID is unique is a task left up to the end user (where the end user is you)."

But AFAIK nowadays it is not widely used - we in production use FDPIC ELF, and there is no visual differences from desktop linuxes.

RoyiAvital commented 5 years ago

It would be great to have a flag specifically for /MT and /MD on Windows.

jpakkane commented 5 years ago

It would be great to have a flag specifically for /MT and /MD on Windows.

We have one now, it is called b_vscrt.

Hi-Angel commented 2 years ago

As a partial solution there're --default-library=static and --prefer-static options. Perhaps the only gotcha is that it doesn't force static build, i.e. build won't fail if there's no certain static version of a library.