Skip to content
العربية

22. Building a standalone executable

To build a single executable from your program that you can give to someone else, who runs it without installing Meem.

  • meem برنامج.م compiles the program and runs it straight away, for trying things out.
  • meem build برنامج.م -o برنامج writes an executable: ./برنامج runs on its own.
  • The file is static by default: it contains the whole C library (musl), so it needs nothing from the machine. --dynamic builds it dynamically against the system’s C library (smaller, and sometimes faster in allocation-heavy programs, but it needs glibc on the machine).
  • The program’s arguments come after -- in a direct run (meem برنامج.م -- سلمى), and after the file name for a built file (./برنامج سلمى).
نافذة الطرفية
meem build عداد.م -o عداد
./عداد

When this site was built, the following example really was built, the resulting file was run on its own, and its output matched the output of the direct run:

عداد.م
لكل ع في مدى(1, 4):
اطبع("العدّ: ", ع)
Output recorded from the compilermeem 18_بناء.م · meem 0.17.3+434e13f
العدّ: 1العدّ: 2العدّ: 3

Also built with meem build when the site was built: a static file of 30.1 kB, run on its own, and its output matched the output above.

A program that greets the name it is given as an argument (نظام.وسائط()), and prints how to use it if it is given no name. Build it, then run it: ./تحية سلمى.

Show the solution
Solution
استورد نظام
وسائط = نظام.وسائط()
اذا طول(وسائط) == 0:
اطبع("الاستعمال: تحية <اسم>")
غير ذلك:
اطبع("أهلاً يا ", وسائط[0], "!")
Output recorded from the compilermeem 18_حل.م -- سلمى · meem 0.17.3+434e13f
أهلاً يا سلمى!

Also built with meem build when the site was built: a static file of 40.1 kB, run on its own, and its output matched the output above.

  • A program that uses خارجي to call a C library other than the standard C library (such as zlib) cannot be built statically: build it with --dynamic, and the library must be installed on the machine that runs it.
  • The built file is for Linux x86_64 only. Windows and macOS are not available in 1.0.

Building: meem build · Command-line options