# How to build Haxe program (and run on HL) with only module-level functions & variables?

**URL:** <https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925>\
**Category:** Haxe\
**Tags:** haxe-hl\
**Created:** [March 1, 2021, 12:23am UTC](https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925 "2021-03-01T00:23:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![uvtc](https://community.haxe.org/user_avatar/community.haxe.org/uvtc/32/1198_2.png) [@uvtc](https://community.haxe.org/u/uvtc)\
**Post date:** [March 1, 2021, 12:23am UTC](https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925/1 "2021-03-01T00:23:05Z")

</div>

I’d like to try out using module-level variables and functions, running them with Hashlink.

Given my-prog.hx:

```haxe
var nm = "World";

function greet(s:String) {
    trace("Hello, " + s + "!");
}

function main() {
    greet(nm);
}

```

How can I compile that to run on Hashlink?

I created an hl.hxml file containing:

```haxe
--hl out.hl

```

And trying `haxe hl.hxml` fails, of course, since I didn’t tell it the filename, but also trying

```
haxe -hl out.hl my-prog.hx

```

fails as well.

What needs to go into my hl.hxml file?

Note, this is using:

```
$ haxe --version
4.2.1+bf9ff69
```

---

<div class="post-metadata">

**Author:** ![LordMZTE](https://community.haxe.org/user_avatar/community.haxe.org/lordmzte/32/1447_2.png) [@LordMZTE](https://community.haxe.org/u/LordMZTE)\
**Post date:** [March 1, 2021, 12:42am UTC](https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925/2 "2021-03-01T00:42:41Z")

</div>

You need to tell haxe the classpath and main Class. Haxe doesn’t really support “Single File” programs like your example (at least to my knowledge), so I’d recommend putting your file into a directory, usually called `src`. You should also rename your file to be `PascalCase`, as the File’s name defines the class name, and class names in haxe must be `PascalCase`. If you don’t want to use a `src` folder, that should work too. This `build.hxml` file should do the trick:

```haxe
-cp . # Set the classpath to the current working directory
-main MyProg # Should use a File called MyProg.hx in the classpath

-hl out.hl # output to a file called out.hl

```

**Note that you need to remove the comments I made for this to be a valid hxml file.**  
In case you wanna put your code into a directory `src` instead, you can set the classpath to `src` instead of `.` (the current working directory).  
The same can also be achieved via these command line arguments

```haxe
haxe \
  -p . \
  --main MyProg \
  --hl out.hl

```

---

<div class="post-metadata">

**Author:** ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)\
**Post date:** [March 1, 2021, 9:29am UTC](https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925/3 "2021-03-01T09:29:58Z")

</div>

> [@LordMZTE](#):
>
> `-cp . # Set the classpath to the current working directory`

No need for that. Current working directory is added to the classpath by default.

---

<div class="post-metadata">

**Author:** ![mark.knol](https://community.haxe.org/user_avatar/community.haxe.org/mark.knol/32/50_2.png) [@mark.knol](https://community.haxe.org/u/mark.knol)\
**Post date:** [March 1, 2021, 9:34am UTC](https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925/4 "2021-03-01T09:34:41Z")

</div>

> [@uvtc](#):
>
> `haxe -hl out.hl my-prog.hx`

- rename file to MyProg.hx (use PascalCasing)
- then run `haxe -hl out.hl -main MyProg` (no need to add “.hx”)

---

<div class="post-metadata">

**Author:** ![uvtc](https://community.haxe.org/user_avatar/community.haxe.org/uvtc/32/1198_2.png) [@uvtc](https://community.haxe.org/u/uvtc)\
**Post date:** [March 1, 2021, 6:12pm UTC](https://community.haxe.org/t/how-to-build-haxe-program-and-run-on-hl-with-only-module-level-functions-variables/2925/5 "2021-03-01T18:12:32Z")

</div>

Nice. I changed the filename to “MyProg.hx”, then in my hl.hxml file put:

```haxe
--hl my-prog.hl
--main MyProg

```

And built+ran like so:

```haxe
haxe hl.hxml
hl my-prog.hl

```

Thanks all!
