Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Distribute my Haxe application with Hashlink?

Tags:

haxe

hashlink

I've got a Haxe Application that I want to make available to people with a Windows system. I use Hashlink to run the Application locally and it works very nicely.

I am wondering if I'm supposed to distribute my Application with Hashlink. Can it build me an .exe?

like image 941
nizzle Avatar asked Mar 10 '17 15:03

nizzle


1 Answers

It looks like generating distributable binary files isn't supported out of the box today (March 10, 2017):

> haxe -main Main -hl main.c
Code generated in main.c automatic native compilation not yet implemented

Hopefully it will be supported soon!

Note: I'm talking about building a final executable using hashlink. An entirely separate approach I do not cover here is the possibility of delivering the hashlink virtual machine with your output hl bitcode.

Sane people stop reading here.

But in the meantime... it is possible to generate binaries with hashlink today if you build hashlink from source.

Warnings:

  • This isn't a generic, cross-platform answer to your question -- it's just my experience on Linux.
  • There will probably soon be a better way than this.
  • But I wanted to jot these notes down even for myself to recall later.

Here's what I had to do on Ubuntu 14.04, 64-bit:

Install prerequisite libraries for building hl (there may be others I already have installed, like build-essential, etc)

sudo apt-get install libvorbis-dev libturbojpeg libsdl2-dev libopenal-dev libssl-dev

Clone and build the mbedtls library: (rev note: b5ba28)

cd ~/dev/
git clone https://github.com/ARMmbed/mbedtls.git
cd mbedtls
make CFLAGS='-fPIC'

Clone the hashlink repo: (rev note: eaa92b)

cd ~/dev/
git clone https://github.com/HaxeFoundation/hashlink.git
cd hashlink

In the # Linux section of the Makefile, ~line 67, add these flags:

CFLAGS += -I ../mbedtls/include
LIBFLAGS += -L../mbedtls/library

Now build with make

If everything works, you'll see two important output files, hl and libhl.so

Ok, at this point, it's easiest if you just build your project in the hashlink directory. For example:

# Still in the hashlink directory
haxe -cp /path/to/my/project -debug -main Main.hx -hl src/_main.c

Now run make hlc, and if everything works, hlc is the output executable (which depends on libhl.so):

cp libhl.so hlc /tmp/
cd /tmp/
./hlc

Prints:

Main.hx:7: Hello world!
like image 58
Jeff Ward Avatar answered Sep 28 '22 11:09

Jeff Ward