Helps you compile HashLink/C code into executable.
Inspired by HLCC, but hlc-compiler uses GCC/Clang while HLCC uses MS Visual Studio.
See also https://github.com/fal-works/hlc-compiler-sample for an example using Heaps.io.
haxelib install hlc-compiler
- Windows
- Mac
- Windows 10 64bit
- Haxe 4.2.3 + Haxelib 4.0.2 (via lix)
- HashLink 1.11.0 (via scoop)
- GCC 11.2.0-9.0.0-r3 (via scoop)
- macOS Monterey
- Haxe 4.2.3 + Haxelib 4.0.2 (via lix)
- HashLink 1.11.0 (via homebrew)
- Clang 13.1.6 (bundled with Xcode)
First you have to output HashLink/C code, e.g. haxe --main Main --hl out/c/main.c
.
For compiling the C code into executable, call haxelib run hlc-compiler
with some options described below.
Basically there is no "mandatory" option, however sometimes you might have to specify some options explicitly depending on your environment.
Directory where your HashLink/C code (including main.c
and hlc.json
) are located.
Defaults to ./
(current working directory).
File path to the *.c
file to be compiled.
The path should be either absolute or relative from --srcDir
directory.
Defaults to main.c
.
File path to the JSON file in your HashLink/C output.
This can be any JSON file that unifies { libs: Array<String> }
where libs
is an array of required library names.
The path should be either absolute or relative from --srcDir
directory.
Defaults to hlc.json
.
Directory path of the output executable.
This will also the destination directory when copying files if --copyRuntimeFiles
is specified.
- If not specified and
--outFile
is specified,--outDir
defaults to the parent directory of--outFile
. - If both not specified, defaults to the current working directory.
Note: hlc-compiler does not clean up old files/directories unless they are to be overwritten.
File path of the output executable.
If --outDir
is sepcified as well, --outFile
should be either absolute or relative from --outDir
directory.
Defaults to ./main
.
Directory that contains required library files (*.hdll
etc).
If not specified:
- On windows, hlc-compiler tries to find the HashLink installation directory from your environment variables (
HASHLINKPATH
,HASHLINK
orHASHLINK_BIN
) as it should contain the files in question. - On Mac, defaults to
/usr/local/lib/
if it exists, as the library files are typically located here. - If nothing found, defaults to
./
(current working directory).
Directory that contains HashLink built-in files to be included (.h
/.c
files, such as hlc.h
).
This will be passed to the C compiler (gcc
/clang
) as an -I
option.
- On Windows: Defaults to directory named
include
in the--hlLibDir
directory (because it should exist in the HashLink directory, to which--hlLibDir
is typically set).null
(will not be passed) if not found. - On Mac: Defaults to
null
, as the files in question are typically located in/usr/local/include/
, which is automaticaly searched by the C compiler at default. - Alternatively you can set an environment variable
C_INCLUDE_PATH
to the path of thisinclude
directory so that it is automatically searched by the C compiler as well. - If something goes wrong, try passing
-v
option and see which directories are searched by the C compiler.
Copies files that are required at runtime (such as dynamic linked libraries) to output directory.
Not set at default.
Additional file to be passed to the C compiler (for instance you might have to pass dbghelp.dll
).
Can be specified multiple times. Not copied even if --copyRuntimeFiles
is set.
Additional file or directory that should be copied if --copyRuntimeFiles
is specified.
The path should be either absolute or relative from the current working directory.
Can be specified multiple times. No effect on compilation.
File path where command-lines should be saved (as batch file on Windows, shell command file on Mac).
Not set (= does not save) at default.
If --saveCmd
is given without any argument value, the file path defaults to ./compile-hlc.bat
or ./compile-hlc.command
in the current directory.
Tries to convert all file/directory paths to relative paths from the current working directory when building command lines.
The C compiler to use.
Allowed values: gcc
, clang
Defaults to gcc
if Windows, clang
if Mac.
Prints verbose log of hlc-compiler.
If using GCC, you can pass any gcc option.
(If Clang, most options should be the same but I'm not sure)
If no -std
option is provided, -std=c11
is automatically added.
Other examples:
-O3
for highest optimization-w
to suppress warnings-v
to see more detailed log of the C compiler-mwindows
for making a Windows GUI app
Assuming that you:
- have compiled your Haxe code with
haxe --main Main --hl out\c\main.c
- installed HashLink in
C:\hashlink\1.11.0\
Then an example would be:
haxelib run hlc-compiler --srcDir out\c --outFile bin\main --hlLibDir c:\hashlink\1.11.0\ --copyRuntimeFiles --exFile c:\Windows\System32\dbghelp.dll --saveCmd out\run_gcc.bat -w
This will:
- run
gcc
command so that your code is compiled intobin\main.exe
- GCC warnings are suppressed (by
-w
)
- GCC warnings are suppressed (by
- copy files that are required at runtime into
bin\
- save command lines as
out\run_gcc.bat
The batch file looks like:
@echo off
if not exist c:\yourDir\bin\ ^
mkdir c:\yourDir\bin\
echo Compiling...
gcc ^
-o c:\yourDir\bin\main ^
-I c:\hashlink\1.11.0\include\ ^
-I c:\yourDir\out\c\ ^
-w ^
-std=c11 ^
c:\yourDir\out\c\main.c ^
c:\Windows\System32\dbghelp.dll ^
c:\hashlink\1.11.0\libhl.lib
echo Copying runtime files...
copy c:\hashlink\1.11.0\libhl.dll c:\yourDir\bin\ > nul
echo Completed.
It depends on your hlc.json
which library files are required.
- File format (something similar to
*.hxml
) for describing options - Haxe API (which is type-safer)
See also: FAL Haxe libraries