COMMUNITY

How do I make my program into a .exe?

Hi there, How do i make my haxe code program into a .exe? I use VSCode and a Windows 7 32 bit. It works fine in the browser, so I think the exe file will work correctly. i can send the code if u want (it is a literal hello world) i am new to haxe also

Hi, your best bet is probably to use the hxcpp target
which allows you to natively compile your code via C++.

How do I install it?

@winner7084 I’m guessing you have a couple files right now, something like Main.hx and build.hxml?

Currently you have a line like --js output.js in your build.hxml, what you want to do is replace that line with --cpp bin, then try running haxe build.hxml. It will probably say Error: Library hxcpp is not installed

To install libraries, you use a tool called haxelib and to install hxcpp you do:
haxelib install hxcpp

After you run that and it finishes downloading, try running haxe build.hxml again. This time it should generate C++ code in a folder called bin/ but it may request to install some other bits, depending what system you have (mac, linux, windows). Most systems don’t include a C++ compiler by default, which is needed to compile the C++ into an exe. Try to follow any instructions it gives (I think on windows you need to install the visual studio compiler or something), and let me know if you get stuck at this step


However. There is an alternative way to generate an exe: it’s possible to package the javascript file you’ve currently got into an exe. The hxcpp approach has some big upsides for potential performance, but that may not matter for your project.

To generate an exe this way, you first need to install node.js (if you don’t already have it): Node.js

Then, open a command prompt to your projects folder and run npm install -g pkg, then pkg <path-to-your-js-file>. So if your js file is output.js, you run pkg output.js. When that finishes, you will get 3 exes, one for windows, one for mac and one for linux :slight_smile:

1 Like