1Mono(mkbundle)                                                  Mono(mkbundle)
2
3
4

NAME

6       mkbundle, mkbundle2 - Creates a bundled executable.
7

SYNOPSIS

9       mkbundle [options] assembly1 [assembly2 ...]
10

DESCRIPTION

12       mkbundle  generates  an  executable  program  that  will contain static
13       copies of the assemblies listed on the command line.  By  default  only
14       the  assemblies  specified  in the command line will be included in the
15       bundle.  To automatically include all of the  dependencies  referenced,
16       use the "--deps" command line option.
17
18       There are two modes of operation, one uses an existing Mono binary or a
19       server-hosted list of binaries and is enabled when you use  either  the
20       --cross, --sdk or the --runtime command line options.
21
22       An  older  mechanism creates a small C stub that links against the lib‐
23       mono library to produce a self-contained executable and  requires  a  C
24       compiler.   It is described in the "OLD EMBEDDING" section below.
25
26       For example, to create a bundle for hello world, use the following com‐
27       mand:
28
29            $ mkbundle -o hello --simple hello.exe
30
31
32       You can configure options to be passed to  the  Mono  runtime  directly
33       into  your  executable, for this, use the --options flag.  For example,
34       the following disables inlining, by passing  the  "-O=-inline"  command
35       line option to the embedded executable:
36
37            $ mkbundle -o hello --options -O=-inline --simple hello.exe
38
39
40       The simple version allows for cross-compiling, this requires a Mono
41       runtime to be installed in the ~/.mono/targets/TARGET/mono to be
42       available.   You can use the "--local-targets" to list all available
43       targets, and the "--cross" argument to specify the target, like this:
44
45            $ mkbundle --local-targets
46            Available targets:
47                 default   - Current System Mono
48                 4.4.0-macosx-x86
49                 4.4.0-debian-8-arm64
50            $ mkbundle --cross 4.4.0-debian-8-powerpc hello.exe -o hello-debian
51
52
53       The  above  will  bundle  your  native  library into hello-debian for a
54       Debian 8 system running on a PowerPC machine.
55
56       We provide pre-packages binaries for Mono  for  various  architectures,
57       which  allow you to cross compile, use the --list-targets to get a list
58       of all targets supported, and use the --fetch-target flag to retrieve a
59       target that you do not have installed, like this:
60
61            $ mkbundle --list-targets
62            Cross-compilation targets available:
63            4.4.0-linux-libc2.13-amd64
64            4.4.0-linux-libc2.13-armel
65            4.4.0-linux-libc2.13-armhf
66            4.4.0-linux-libc2.13-i386
67            4.4.0-macos-10.7-amd64
68            4.4.0-macos-10.7-i386
69            4.4.2-linux-libc2.13-amd64
70            4.4.2-linux-libc2.13-armel
71            4.4.2-linux-libc2.13-armhf
72            4.4.2-linux-libc2.13-i386
73            4.4.2-macos-10.7-amd64
74            4.4.2-macos-10.7-i386
75
76            $ mkbundle --fetch-target 4.4.2-macos-10.7-i386
77
78
79       And  then you can produce a binary that will run on 32-bit Mono on Mac‐
80       OS:
81
82            $ mkbundle --cross 4.4.2-macos-10.7-i386 hello.exe -o hello-macos
83
84
85       Downloaded targets are stored ~/.mono/targets directory.
86

OPTIONS

88       --config FILE
89              Specifies that a DLLMAP Mono config  file  must  be  bundled  as
90              well.    In  the  simple  and cross compiler modes, if no config
91              file is specified the one  for  the  current  target  is  picked
92              (either  the  system  one in the case of the simple mode, or the
93              one that came from the cross compilation target  for  the  cross
94              compiling mode).
95
96       --config-dir DIR
97              When  passed,  DIR  will be set for the MONO_CFG_DIR environment
98              variable
99
100       --cross target
101              Use this to request mkbundle generate a  cross-compiled  binary.
102              It Creates a bundle for the specified target platform.  The tar‐
103              get must be a directory in ~/.mono/targets/ that contains an SDK
104              installation  as produced by the mono-package-runtime tool.  You
105              can get a list of the precompiled versions of the runtime  using
106              --list-targets  and  you  can  fetch a specific target using the
107              --fetch-target command line option.
108
109              This flag is mutually exclusive with  --sdk  which  is  used  to
110              specify  an  absolute  path to resolve the Mono runtime from and
111              the --runtime option which is used  to  manually  construct  the
112              cross-platform package.
113
114       --deps This option will bundle all of the referenced assemblies for the
115              assemblies listed on the command line option.  This is useful to
116              distribute a self-contained image.
117
118       --env KEY=VALUE
119              Use  this to hardcode an environment variable at runtime for KEY
120              to be mapped to VALUE.   This is useful in scenarios  where  you
121              want  to  enable certain Mono runtime configuration options that
122              are controlled by environment variables.
123
124       --fetch-target target
125              Downloads a precompiled runtime for the  specified  target  from
126              the Mono distribution site.
127
128       --i18n encoding
129              Specified  which  encoding  tables  to ship with the executable.
130              By default, Mono ships the supporting I18N.dll assembly and  the
131              I18N.West.dll  assembly.   If your application will use the Sys‐
132              tem.Text.Encoding.GetEncoding with encodings other than the West
133              encodings, you should specify them here.
134
135              You  can  use  the  none  parameter  to request that no implicit
136              encodings should be bundled, including the supporting  I18N.dll,
137              use this option if you have ran a linker on your own.
138
139              You can use the all flag to bundle all available encodings.
140
141              Or  you  can  use a comma delimited list of the workds CJK, Mid‐
142              West, Other, Rare and West to specificy  which  encoding  assem‐
143              blies to distribute.
144
145       -L path
146              Adds  the  `path'  do the search list for assemblies.  The rules
147              are the same as for the compiler -lib: or -L flags.
148
149       --library [LIB,]PATH
150              Embeds the dynamic library file pointed to by `PATH' and option‐
151              ally  give it the name `LIB' into the bundled executable.   This
152              is used to ship native library dependencies that are unpacked at
153              startup  and  loaded from the runtime. Multiple libraries should
154              be specified in dependency order, where later ones on  the  com‐
155              mand line depend on earlier ones.
156
157       --lists-targets
158              Lists  all  of  the  available  local  cross compilation targets
159              available as  precompiled  binaries  on  the  Mono  distribution
160              server.
161
162       --local-targets
163              Lists all of the available local cross compilation targets.
164
165       --cil-strip PATH
166              Provides  a CIL stripper that mkbundle will use if able to.  The
167              intended use is to help reduce file size on AOT.
168
169       --in-tree path/to/mono/source/root
170              Provides mkbundle with a mono source repository  from  which  to
171              pull  the necessary headers for compilation.  This allows mkbun‐
172              dle to run out of the project's source tree, useful for  working
173              with multiple runtimes and for testing without installing.
174
175       --managed-linker PATH
176              Provides  mkbundle  access to a managed linker to preprocess the
177              assemblies.
178
179       --machine-config FILE
180              Uses the given FILE as the machine.config file for the generated
181              application.   The  machine  config contains an XML file that is
182              used by System.Configuration APIs to configure the  .NET  stack.
183              Typically this is $prefix/etc/mono/4.5/machine.config.
184
185              If  you want to disable this automatic bundling, you can use the
186              --no-machine-config flag.  In  the  simple  and  cross  compiler
187              modes,  if  no  machine.config file is specified the one for the
188              current target is picked (either the system one in the  case  of
189              the simple mode, or the one that came from the cross compilation
190              target for the cross compiling mode).
191
192       --no-config
193              In simple or cross compiling mode, this prevents  mkbundle  from
194              automatically bundling a config file.
195
196       --nodeps
197              This  is  the default: mkbundle will only include the assemblies
198              that were specified on the command line to reduce  the  size  of
199              the resulting image created.
200
201       --no-machine-config
202              In  simple  or cross compiling mode, this prevents mkbundle from
203              automatically bundling a machine.config file.
204
205       -o filename
206              Places the output on `out'.  If the flag -c is  specified,  this
207              is the C host program.  If not, this contains the resulting exe‐
208              cutable.
209
210       --options OPTS
211              Since the resulting executable will be treated as  a  standalone
212              program,  you  can use this option to pass configuration options
213              to the Mono runtime and  bake  those  into  the  resulting  exe‐
214              cutable.  These options are specified as OPTS.
215
216              You  can use the above to configure options that you would typi‐
217              cally pass on the command line to Mono, before the main  program
218              is executed.
219
220              Additionally, users of your binary can still configure their own
221              options by setting the MONO_ENV_OPTIONS environment variable.
222
223       --sdk SDK_PATH
224              Use this flag to specify a path from which mkbundle will resolve
225              the Mono SDK from.   The SDK path should be the prefix path that
226              you used to configure a Mono installation.   And would typically
227              contain  files lik SDK_PATH/bin/mono , SDK_PATH/lib/mono/4.5 and
228              so on.
229
230              When this flag is specified, mkbundle will resolve the  runtime,
231              the  framework  libraries, unmanaged resources and configuration
232              files from the files located in this directory.
233
234              This flag is mutually exlusive with --cross
235
236       --target-server SERVER
237              By default the mkbundle tool will download from  a  Mono  server
238              the  target runtimes, you can specify a different server to pro‐
239              vide cross-compiled runtimes.
240
241       --mono-api-struct-path FILE
242              FILE points to a file with the definition of  the  BundleMonoAPI
243              structure  which  contains the required pointers to various Mono
244              API functions used throughout the generated code. This mechanism
245              is  meant  to be used by third parties which embed the Mono run‐
246              time and dynamically load and  initialize  it  as  part  of  the
247              application  startup,  in  which  case the Mono APIs will not be
248              available for the shared library loader and the bundle will fail
249              to  work  (one  example of such an embedding third party is Xam‐
250              arin.Android).
251
252              After providing the definition FILE, the embedder must call  the
253              void  initialize_mono_api  (const  BundleMonoAPI *info) function
254              found in the generated  code  before  calling  void  mono_mkbun‐
255              dle_init (). The structure passed to initialize_mono_api doesn't
256              need to be dynamically allocated as its contents  is  copied  to
257              the  local structure in the generated code and no pointer to the
258              passed structure is retained or used  after  initialize_mono_api
259              returns.
260
261              The  list  of  pointers  is not documented here. Instead, please
262              look at the  bundle-mono-api.inc  file  found  in  the  mkbundle
263              source  directory  in your Mono source tree (mcs/tools/mkbundle)
264              or      in       the       Mono's       GitHub       repository,
265              https://github.com/mono/mono/blob/master/mcs/tools/mkbundle/bun
266              dle-mono-api.inc
267
268              Please note that your structure must match the one  expected  by
269              your version of the Mono runtime.
270
271              The  file  must also define the mkbundle_log_error function with
272              the following signature:
273
274                   static void mkbundle_log_error (const char *format, ...) {}
275
276              The function should implement logging API specific to the embed‐
277              der.
278
279

OLD EMBEDDING

281       The old embedding system compiles a small C stub that embeds the C code
282       and compiles the resulting executable using the system compiler.   This
283       requires  both a working C compiler installation and only works to bun‐
284       dle binaries for the current host.
285
286       The feature is still available, but we recommend  the  simpler,  faster
287       and more convenient new mode.
288
289       For example, to create a bundle for hello world, use the following com‐
290       mand:
291
292            $ mkbundle -o hello hello.exe
293
294       The above will pull hello.exe into a  native  program  called  "hello".
295       Notice that the produced image still contains the CIL image and no pre‐
296       compilation is done.
297
298       In addition, it is possible to control whether mkbundle should  compile
299       the  resulting executable or not with the -c option.  This is useful if
300       you want to link additional libraries or control the  generated  output
301       in  more detail. For example, this could be used to link some libraries
302       statically:
303
304            $ mkbundle -c -o host.c -oo bundles.o --deps hello.exe
305
306            $ cc host.c bundles.o /usr/lib/libmono.a -lc -lrt
307
308       You may also use mkbundle to generate a bundle you can use when  embed‐
309       ding  the Mono runtime in a native application.  In that case, use both
310       the -c and --nomain options.  The resulting host.c file will not have a
311       main() function.  Call mono_mkbundle_init() before initializing the JIT
312       in your code so that the bundled assemblies are available to the embed‐
313       ded runtime.
314

OLD EMBEDDING OPTIONS

316       These  options can only be used instead of using the --cross, --runtime
317       or --simple options.
318
319       -c     Produce the stub file, do not compile the resulting stub.
320
321       -oo filename
322              Specifies the name to be used for the helper  object  file  that
323              contains the bundle.
324
325       --keeptemp
326              By default mkbundle will delete the temporary files that it uses
327              to produce the bundle.  This option keeps the file around.
328
329       --nomain
330              With the -c option, generate the  host  stub  without  a  main()
331              function.
332
333       --static
334              By  default  mkbundle  dynamically links to mono and glib.  This
335              option causes it to statically link instead.
336
337       -z     Compresses the assemblies  before  embedding.  This  results  in
338              smaller   executable  files,  but  increases  startup  time  and
339              requires zlib to be installed on the target system.
340
341

AOT Options

343       These options support an mkbundle using  AOT  compilation  with  static
344       linking. A native compiler toolchain is required.
345
346       --aot-runtime PATH
347              Provide  the  path  to the mono runtime to use for AOTing assem‐
348              blies.
349
350       --aot-dedup
351              (Experimental) Deduplicate AOT'ed methods based on a unique man‐
352              gling of method names.
353
354       --aot-mode MODE
355              MODE  can  be  either  "full"  or "llvmonly" at this time.  Cur‐
356              rently, mkbundle supports three  AOT  modes.  The  default  mode
357              (this  option unset) will AOT methods but will fall back on run‐
358              time codegen where it is much faster or offers a more full  com‐
359              patibility  profile. The "full" setting will generate the neces‐
360              sary stubs to not require runtime  code  generation.  The  "llv‐
361              monly"  setting  does  the  same,  but  forces all codegen to go
362              through the llvm backend.
363
364

WINDOWS

366       If you are using the old embedding on Windows systems, it  possible  to
367       use  a  Unix-like  toolchain  like  cygwin's and install gcc, gcc-mingw
368       packages or use Visual Studio  2015/2017  VC  toolchain  together  with
369       Clang  for  Visual  Studio  as assembler.  Clang can be installed as an
370       individual component, "Clang/C2", using Visual Studio installer.
371
372       Using Visual Studio toolchain, mkbundle will, by  default,  use  latest
373       installed  Visual Studio compiler and linker as well as Windows SDK. If
374       executed from one of  the  Visual  Studio  developer  command  prompts,
375       mkbundle  will  retrieve  information directly from that build environ‐
376       ment.
377

ENVIRONMENT VARIABLES

379       AS     Assembler command. The  default  is  "as".  For  Visual  Studio,
380              default is "clang.exe".  If "clang.exe" for Visual Studio is not
381              installed, mkbundle will fall back using "as".
382
383       CC     C compiler command. The default is "cc"  for  Linux,  "gcc"  for
384              cygwin and "cl.exe" for Visual Studio.
385
386       MONO_BUNDLED_OPTIONS
387              Options  to  be passed to the bundled Mono runtime, separated by
388              spaces. See the mono(1) manual page or run mono --help.
389

WINDOWS VISUAL STUDIO ENVIRONMENT VARIABLES

391       VisualStudioVersion
392              Visual Studio version used in mkbundle build.   Default,  latest
393              installed Visual Studio version.  Values, "14.0" for Visual Stu‐
394              dio 2015 or "15.0" for Visual Studio 2017.
395
396       WindowsSdkVersion
397              Windows SDK version used in  mkbundle  build.   Default/unknown,
398              latest  installed  Windows  SDK.  Values, "8.1", "10.0.10240.0",
399              "10.0.15063.0" etc.
400
401       VSCMD_ARG_TGT_ARCH
402              Output   target   architecture   used   in    mkbundle    build.
403              Default/unknown,  use  architecture  of  .NET  runtime executing
404              mkbundle.  Values, "x86" or "x64".  NOTE, when  running  from  a
405              Visual  Studio  command  prompt, this variable should already be
406              set by the command prompt and match the rest of that build envi‐
407              ronment.
408
409       INCLUDE
410              Override  all  custom  include paths passed to "cl.exe".  Prede‐
411              fined by Visual Studio developer command prompt or auto detected
412              by mkbundle when undefined.
413
414       LIB    Override  all custom library paths passed to "link.exe".  Prede‐
415              fined by Visual Studio developer command prompt or auto detected
416              by mkbundle when undefined.
417
418       MONOPREFIX
419              Use  a  custom  Mono SDK install root matching the output target
420              architecture  (x86/x64).   Default,  mkbundle  will   look   for
421              installed Mono SDK’s matching targeted architecture.
422
423       MONOLIB
424              Use  a  different  mono  library name or an absolute path to the
425              mono library passed  to  linker.   Default,  mkbundle  will  use
426              default  mono  library name depending on mkbundle dynamic/static
427              use case.  NOTE, supplied mono library needs to  match  mkbundle
428              dynamic/static use case and target architecture.
429
430       VCCRT  Override  C-runtime  library  linker  settings.   Default  "MD",
431              mkbundle will use dynamic C-runtime linking on Windows  compati‐
432              ble  with Mono SDK distribution.  If a custom built Mono runtime
433              using static C-Runtime linkage is used, setting this variable to
434              "MT" will link using static C-runtime libraries.
435
436       VCSUBSYSTEM
437              Override Windows subsystem.  Default, "windows". If console sub‐
438              system is preferred, use "console".  NOTE, if console output  is
439              expected  from  output  target process then set this variable to
440              "console".
441

FILES

443       This program will load referenced assemblies  from  the  Mono  assembly
444       cache.
445
446       Targets are loaded from ~/.mono/targets/TARGETNAME/mono
447

BUGS

MAILING LISTS

450       Visit    http://lists.ximian.com/mailman/listinfo/mono-devel-list   for
451       details.
452

WEB SITE

454       Visit: http://www.mono-project.com for details
455

SEE ALSO

457       mcs(1),mono(1),mono-config(5).
458
459
460
461
462
463                                                                Mono(mkbundle)
Impressum