1

I tried haxe on MacOS, and setup the toolchain correctly, etc., but when i tried to compile a file, i got an error, so i tried again with an example in the tutorial (here: https://haxe.org/documentation/introduction/language-introduction.html), and got the same error, which is:

Type not found : HelloWorld

for the command:

haxe -main HelloWorld -js HelloWorld.js

to compile the file:

class HelloWorld {
    static public function main() {
      trace("Hello World");
    }
}

What am i doing wrong?

  • This could happen if the file isn't named HelloWorld.hx or if your terminal isn't in the directory with the haxe file (you would need to `cd` into it). – 5Mixer Mar 04 '17 at 23:09
  • FYI, you can pass `-main` a fully qualified class name, or a filename (related: http://stackoverflow.com/questions/35952115). And while that's fine for a quick test, long term you're probably better off explicitly specifying your class path(s) with `-cp` – Jeff Ward Mar 05 '17 at 00:35

1 Answers1

2

Make sure that your haxe source file is named as HelloWorld.hx and your working directory is at where the source file is, when you run the compile command

KevinResoL
  • 982
  • 8
  • 19
  • So the name of the main class must be the same as the name of the file? – Spooikypok_Dev Mar 05 '17 at 21:44
  • 1
    For starters, your filename should always be same as the class name. But you can actually put more than on class in a single file. Check out the Module section in the manual: https://haxe.org/manual/type-system-modules-and-paths.html – KevinResoL Mar 06 '17 at 08:01