Getting started with Haxe targetting HashLink

John Gabriele


Haxe can compile to many different target platforms, one of which is its very own HashLink VM. This doc is a guide to installing the HashLink VM onto Debian GNU/Linux (the “Testing” distribution), compiling your Haxe code to HashLink bytecode, and then running that bytecode on the HashLink VM (aka “using HL/JIT”).

Note: The Haxe HashLink target can also produce C code which you’d then compile with a C compiler like GCC. This use of HashLink is called “HL/C”, in contrast to the above “HL/JIT”, which we’re using in this doc.


Haxe 4

To install the latest version of Haxe onto GNU/Linux, see my getting started with Haxe doc.

Other Prereqs via apt

We’ll build the latest HashLink release from source and install into /usr/local. But before that, per the HashLink README, make sure you have a handful of recommended libraries installed:

# apt install libpng-dev libturbojpeg0-dev libvorbis-dev
# apt install libopenal-dev libsdl2-dev
# apt install libmbedtls-dev libuv1-dev

Install HashLink

No longer as root (from the above use of apt), download the latest binary release of HashLink (approx 4 MB) and build it like so:

mv hashlink-1.10.tar.gz ~/opt
cd ~/opt
tar xzf hashlink-1.10.tar.gz
cd hashlink-1.10

If upgrading: first, from your previous hashlink version’s directory (in ~/opt/hashlink-1.X), as root, run make uninstall there.

As root, install HashLink:

# make install

HL will be installed into /usr/local. Then run

# ldconfig

so the system can properly find the libraries just copied to /usr/local/lib (ldconfig searches the library directories and updates /etc/

If you want to use HL/C you’ll need to install via haxelib (not as root) the “hashlink” library:

$ haxelib install hashlink

This provides the build tools to make HL/C work, analogous to how the hxcpp and hxjava libraries provide the build tools for the C++ and Java targets, respectively. See the currently-installed version:

$ haxelib list hashlink

Try it out

You should now have hl installed:

$ which hl

$ hl
HL/JIT 1.10.0 (c)2015-2019 Haxe Foundation
  Usage : hl [--debug <port>] [--debug-wait] <file>

Try it out on some code. cd path/to/my-proj. Create a src/Main.hx file containing:

class Main {
    public static function main() {
        trace("Hello, World!");

And an hl.hxml file containing:

-p src
-m Main
--hl out.hl

Then (instead of having to type out haxe -p src -main Main --hl out.hl (and then run via hl out.hl)), you can build and run in one shot from your project’s top-level directory:

haxe hl.hxml && hl out.hl

getting this output:

Main.hx:3: Hello, World!