app.c interacts with a haxe generated shared library compiled with build-library.hxml
I've included a makefile for compiling on macOS (make -f makefile.mac
), however the example is minimal – just a single C file and shared library so should work with any C toolchain or platform, to compile from scratch:
Requirements:
- haxe 4.2
- hxcpp 4.2.*
Steps:
-
Install hxcpp dependency:
haxelib install build-library.hxml
(this will install hxcpp to .haxelib/) -
Compile the haxe code into a dynamic library:
haxe build-library.hxml
, this will generate a shared library in haxe-bin/ ready for embedding in a native application -
Compile app.c with your favorite C compiler and link it to the shared library generated by hxcpp
For macOS this is
# compile app.c to 'main` executable and link with shared library clang app.c -o main haxe-bin/Main-debug.dylib # after compiling you need to tell app where it can find the shared library at runtime install_name_tool -change Main-debug.dylib @executable_path/haxe-bin/Main-debug.dylib app
For linux this might be something like
# compile app.c to 'main` executable and link with shared library gcc app.c -o main haxe-bin/Main-debug.so -Wl,-rpath,haxe-bin/
And run with
./app