7 Compiler Usage

Basic Usage

The Haxe Compiler is typically invoked from command line with several arguments which have to answer two questions:

  • What should be compiled?
  • What should the output be?

To answer the first question, it is usually sufficient to provide a class path via the -p <path> argument, along with the main class to be compiled via the -m <dot_path> argument. The Haxe Compiler then resolves the main class file and begins compilation.

The second question usually comes down to providing an argument specifying the desired target. Each Haxe target has a dedicated command line switch, such as --js <file_name> for JavaScript and --php <directory> for PHP. Depending on the nature of the target, the argument value is either a directory path (for --php, --cpp, --cs, and --java) or a file name.

Common arguments


  • -p <path> (or --class-path <path>) Add a class path where .hx source files or packages (sub-directories) can be found.
  • -L <library_name> (or --library <library_name>) Add a Haxelib library. By default the most recent version in the local Haxelib repository is used. To require a specific library version use -L library_name:version. To require a version from git use -L library_name:git:https://github.com/user/project.git#commit where the optional #commit can be a branch, tag or commit hash.
  • -m <dot_path> (or --main <dot_path>) Set the main class.
  • -D <var[=value]> (or --define <var[=value]>) Define a conditional compilation flag.


  • --js <file_name.js> Generate JavaScript source code in specified file.
  • --swf <file_name.swf> Generate the specified file as Flash .swf.
  • --neko <file_name.n> Generate Neko binary as specified file.
  • --php <directory> Generate PHP source code in specified directory. Use -D php7 for PHP7 source code.
  • --cpp <directory> Generate C++ source code in specified directory and compiles it using native C++ compiler.
  • --cs <directory> Generate C# source code in specified directory and compiles it using native C# compiler.
  • --java <directory> Generate Java source code in specified directory and compiles it using the Java Compiler. Add -D jvm to generate JVM byte code directly bypassing Java compilation step.
  • --jvm <file_name.jar> Generate JVM bytecode as a jar file.
  • --python <file_name.py> Generate Python source code in the specified file.
  • --lua <file_name.lua> Generate Lua source code in the specified file.
  • --hl <file_name.hl> Generate HashLink byte code in specified file.
  • --cppia <file_name.cppia> Generate the specified script as a cppia file.
  • -x <file> Shortcut for compiling and executing a Neko file.
  • --no-output Compile but do not generate any file.
  • --interp Interpret the program using internal macro system.
Other global arguments
  • --run <module> [args...] Compile and execute a Haxe module with command line arguments.
  • --xml <file> Generate XML types description. Useful for API documentation generation tools like Dox.
  • -v (or --verbose) Turn on verbose mode.
  • --dce <std|full|no> Set the Dead Code Elimination mode (default std).
  • --debug Add debug information to the compiled code.
  • -r <file>[@name] (or --resource <file>[@name]) Add a named resource file.
  • --prompt Prompt on error.
  • --cmd <command> Run the specified shell command after a successful compilation.
  • --no-traces Don't compile trace calls in the program.
  • --display Display code tips to provide completion information for IDEs and editors.
  • --times Measure compilation times.
  • --no-inline Disable inlining.
  • --no-opt Disable code optimizations.
  • --remap <package:target> Remap a package to another one.
  • --macro Call the given initialization macro before typing anything else.
  • --wait <host:port> Wait on the given port for commands to run (see Completion server).
  • --connect <host:port> Connect on the given port and run commands there (see Completion server).
  • -C <dir> (or --cwd <dir>) Set current working directory.
Target specific arguments
  • -D php-front=<filename> Select the name for the php front file.
  • -D php-lib=<filename> Select the name for the php lib folder.
  • -D php-prefix=<name> Prefix all classes with given name.
  • --swf-version <version> Change the SWF version.
  • --swf-header <header> Define SWF header (width:height:fps:color).
  • --swf-lib <file> Add the SWF library to the compiled SWF.
  • --swf-lib-extern <file> Use the SWF library for type checking.
  • --flash-strict More type strict flash API.
  • --java-lib <file> Add an external JAR or class directory library.
  • --net-lib <file>[@std] Add an external .NET DLL file.
  • --net-std <file> Add a root std .NET DLL search path.
  • --c-arg <arg> Pass option arg to the native Java/C# compiler.
Trivia: Run commands after compilation

Use --cmd to run the specified command after a successful compilation. It can be used to run (testing) tools or to directly run the build, e.g. --cmd java -jar bin/Main.jar (for Java), --cmd node main.js (for Node.js) or --cmd neko Main.n (for Neko) etc.

Global compiler configuration macros:

In order to include single modules, their paths can be listed directly on command line or in hxml: haxe ... ModuleName pack.ModuleName. For more specific includes or excludes, use these initialization macros:

  • --macro include(pack:String, recursive=true, ?ignore:Array<String>, ?classPaths:Array<String>, strict=false) Includes all modules in package pack in the compilation. If recursive is true, the compiler recursively adds all sub-packages.
  • --macro exclude(pack:String, recursive=true Exclude a specific class, enum, or all classes and enums in a package from being generated. Excluded types become extern. If recursive is true, the compiler recursively excludes all sub-packages.
  • --macro excludeFile(fileName:String) Exclude classes and enums listed from given external file (one per line) from being generated.
  • --macro keep(?path:String, ?paths:Array<String>, recursive=true) Marks a package, module or sub-type dot path to be kept by DCE. This also extends to the sub-types of resolved modules. If recursive is true, the compiler recursively keeps all sub-packages for package paths.
  • --macro includeFile(file:String, position) Embed a JavaScript file at compile time. position can be either "top", "inline" or "closure".

The full documentation of these methods can be found in the haxe.macro.Compiler API documentation.

  • haxe --version Print the current Haxe compiler version.
  • haxe --help Display this list of options.
  • haxe --help-defines Print help for all compiler specific defines.
  • haxe --help-metas Print help for all compiler metadata.
Related content