12.13.2 HashLink/C Compilation

Haxe supports two modes of compilation for HashLink:

  • Compilation to HashLink bytecode. This mode has a very fast compilation time, so it is suitable for daily development.
  • Compilation to HashLink/C code, compiled with a native compiler to a regular executable. This mode results in the best performance, so it is suitable for final releases.
HashLink bytecode

Compiling to HashLink bytecode is achieved by specifying a .hl output in the --hl argument:

haxe --main Main --hl output.hl

This produces a single output.hl bytecode file, which can be executed with the HashLink JIT virtual machine with:

hl output.hl
HashLink/C code

Before compiling to Hashlink/C, the hashlink haxelib library must be installed. See here for details.

Haxe code can then be compiled to HashLink/C code by specifying .c output in the --hl argument:

haxe --main Main --hl out/main.c

This produces files in the out directory, which can be compiled to a native executable with a C compiler such as gcc.

gcc -O3 -o hello -std=c++ -I out out/main.c -lhl [-L/path/to/required/hdll]

Note that during native compilation, the HL library must be linked. See here for information on obtaining Hashlink binaries.

Hashlink/C with Visual Studio

On Windows, to make compilation easier, it is also possible to generate Visual Studio project files.

First, the HASHLINK environment variable must be set up, pointing to the Hashlink install location. This is necessary as it is used within the project files to locate the Hashlink sources.

The project files can then be generated by adding the -D hlgen.makefile define to the compilation command:

haxe --main Main --hl out/main.c -D hlgen.makefile=vs2017

This produces a main.sln file in the out directory, which can simply be opened in Visual Studio and built without any extra setup.