Please clickthe above oh my x Follow this public account
In modern software development, cross-platform building and distribution has always been a challenging pain point. Although many languages and frameworks offer cross-platform capabilities, most require sacrificing performance or relying on large runtime environments. C/C++, as high-performance system languages, are irreplaceable in terms of low-level control and execution efficiency, but they require cumbersome multi-platform compilation and packaging processes for cross-platform building and distribution.
Cosmopolitan C Library (abbreviated as Cosmopolitan or Cosmo) was born in this context. Developed by Justine Tunney, its goal is to allow C programs to compile into a special binary formatβAPE (Actually Portable Executable), which can run natively on Windows, Linux, macOS, FreeBSD, OpenBSD, NetBSD, and even BIOS, truly achieving ‘compile once, run anywhere’.
The Core Value of Cosmopolitan
The main problems that Cosmopolitan addresses are as follows:
- Unified Distribution Developers only need to build one binary file, which can run directly on multiple operating systems, reducing the cost of maintaining multi-platform build systems.
- No Dependencies No virtual machines or interpreters are required; it generates native binary files that are lighter and more efficient.
- Performance Assurance Compared to other libc implementations, Cosmopolitan employs vectorization optimizations in basic libraries like string handling, allowing common CLI tools to achieve even higher performance.
Running Cosmopolitan Applications
To lower the barrier to using Cosmopolitan, x-cmd provides the <span>x cosmo</span> module, which offers unified running, installation, and management capabilities for applications compiled with Cosmopolitan. Compared to manually downloading and invoking APE files, <span>x cosmo</span> is more in line with daily usage habits, allowing users to quickly experience and manage Cosmo applications.
1. Basic Running
<span>x cosmo</span> The simplest usage is to directly run an application compiled with Cosmopolitan. For example, to run Lua:
x cosmo lua [parameters]
If this is the first execution, the tool will automatically download the APE loader and cache it locally, then run it directly. Users do not need to worry about the underlying binary format or compatibility issues.
Users can also select the program to run in interactive mode:
x cosmo
After entering the TUI interface, users can select the Cosmo application to run using the keyboard.
2. Installation and Deployment
Unlike simple running, <span>x cosmo</span> also supports installing programs to a specified directory or PATH for long-term use.
- Install Lua to a specified directory:
x cosmo -i lua ~/tools
This way, users can find the Lua executable in <span>~/tools</span>.
- Select an installation directory in PATH and place
<span>make</span>:
x cosmo -i make
The tool will interactively list all directories in PATH, and after the user selects a directory, the program will automatically install <span>make</span>, making it ready to use.
This method is particularly suitable for team environments, allowing developers to quickly deploy a set of commonly used tools on their development machines or container environments.
3. Global Environment Management
<span>x cosmo</span> provides package manager-like functionality, allowing applications to be added or removed from the global environment.
- Add a tool to the global environment:
x cosmo --use lua
- Remove from the global environment:
x cosmo --unuse lua
This way, users do not need to manually modify PATH, making it easy to enable or disable an application system-wide.
4. Program Location and Information Query
- Query the installation path of a specific application:
x cosmo --which lua
- Interactively view all available applications:
x cosmo --ls
- List all supported Cosmo applications:
x cosmo --ll
- View information about the Cosmopolitan author:
x cosmo --author
These features allow <span>x cosmo</span> to function both as a tool runner and as a ‘Cosmo application indexer’, helping users quickly locate and understand applications.
5. Usage Scenario Examples
- Quickly Experience Cross-Platform Applications New users only need to use
<span>x cosmo</span>to experience a zero-dependency cross-platform program. - Team Development Environment Teams can use
<span>x cosmo -i</span>to batch install tools (such as<span>make</span>,<span>vim</span>,<span>lua</span>), avoiding inconsistencies in the environment due to operating system differences. - Temporary Use of Tools For programs needed occasionally, users can use
<span>x cosmo --use</span>to enable globally, and then<span>x cosmo --unuse</span>to disable, avoiding environment pollution. - Containers and CI/CD Environments When building container images or CI/CD pipelines, directly install binaries via
<span>x cosmo</span>to reduce dependency layers and enhance image lightweightness.
Typical Application Scenarios
1. Cross-Platform Distribution
Cosmo applications compiled by developers can be directly delivered to users, managed with <span>x cosmo</span>, without distinguishing between operating systems, significantly reducing publishing and maintenance costs.
2. Research and Education
Teachers can quickly distribute experimental tools using <span>x cosmo</span>, ensuring students achieve consistent execution results across different systems.
3. Operations and Emergency Response
Operations personnel can quickly install necessary tools (such as <span>curl</span>, <span>vim</span>) on different platforms using <span>x cosmo</span>, without dealing with complex dependency issues, making it suitable for emergency scenarios.
π Welcome to join our user communication group π
Here, you can:π’ Be the first to know about the latest updates and event informationπ€ Meet peers and share practical experiencesπ Discuss industry trends and expand your networkCircle
π How to join?π· Scan the QR code below to join the group immediately!

Looking forward to your joining, let’s grow together!π
Please clickthe following Read the original text, to get a more detailed introduction and recommended readings. Please indicate the original text link: https://www.x-cmd.com/mod/cosmo/cookbook-1