Haxe Target-Specific Getting-Started Tutorials

Getting started with Haxe targetting HashLink

You want to compile your Haxe code to HashLink bytecode, then run it 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 sometimes called “HL/C”, in contrast to the above “HL/JIT”, which we’re using in this doc.


Haxe 4

We want to use a preview release of Haxe 4 for use with HashLink. Go to the Haxe Download page and click the “(View all versions)” link at the top. Then go to “Haxe 4.0.0-preview.5” and download the Linux 64-bit binaries. Install like so:

mv path/to/haxe-4.0.0-preview.5-linux64.tar.gz ~/opt
cd ~/opt
tar xzf haxe-4.0.0-preview.5-linux64.tar.gz
cd haxe_20181012132630_7eb789f/
cp haxe haxelib ~/bin

Then, so haxe can find its std library:

cd ~/opt
ln -s haxe_20181012132630_7eb789f haxe

and in your ~/.bashrc, add:

export HAXE_STD_PATH="$HOME/opt/haxe/std"

Finally, set up haxelib:

haxelib setup

accepting the default ~/haxelib directory name (where haxelib will store installed library files).

If you don’t already have it installed, you’ll need to apt install neko, as haxelib requires it.


To upgrade to a newer preview release:

  • As described above: download, unpack, and copy the newer haxe and haxelib binaries into your ~/bin.
  • rm the haxe symlink in ~/opt and make a new one pointing to the newly unpacked haxe_2018... directory.

Try it out

$ haxe --version

$ haxelib version


We’ll build the latest HashLink release from source. As of 2018-10, this is HashLink 1.7. But to do that, per the HashLink README, first install a few recommended libraries:

# 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, download the latest binary release of HashLink and build it like so:

To upgrade: first, from your previous hashlink version’s directory, as root, run make uninstall.

As root, install HashLink:

# make install

HL will be installed into /usr/local. Also run:

# ldconfig

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

If you want to use HL/C you’ll need to install via haxelib 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.

Try it out

You should now have hl installed:

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

Try it out on some code:

cd path/to/my-proj
cat Main.hx

which is:

Then build and run it:

haxe -hl out.hl -main Main
hl out.hl

to get the output:

Main.hx:3: Hello, World!