Getting started with Haxe targetting C++

John Gabriele


Haxe can compile to many different target platforms. This doc is a guide to compiling your Haxe code to C++ and then building it on Debian GNU/Linux (the “testing” distribution).


Haxe 4

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

Native Build Tools

Install the usual GNU compiler, linker, and other build tools;

# apt install build-essential


hxcpp (source code) is the runtime support for the Haxe compiler’s C++ back-end.

Install it:

haxelib install hxcpp

Try it out


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 a cpp.hxml file containing:

-p src
-m Main
--cpp out

and make that “out” directory: mkdir out.

Now build and run the resulting executable:

$ haxe cpp.hxml
$ ./out/Main

getting this output:

Main.hx:3: Hello, World!

More Info

For the full docs, see the C++ target chapter of the manual.