I just began to learn Haxe, but I have encountered Compile error.
Main.hx
package helloworld;
import js.Lib;
class Main {
static function main() {
Lib.alert("Hello World");
}
}
Please be careful about the target class is helloworld.Main.
build.hxml
-js bin/HelloWorld.js
-cp src
-main helloworld.Main
-debug
Build process log
Building HelloWorld_p140627
Running Pre-Build Command Line...
cmd: C:\HaxeToolkit\haxe\haxe.exe X:\tmp\HelloWorld_p140627\build.hxml
Class not found : helloworld.Main
Build halted with errors.
Done(1)
Why? The class helloworld.Main is surely exist. I cannot even say "hello, world"?
Update now that I can see a screenshot of your project:
You are trying to compile "helloworld.Main", that means a class called "Main" in the package "helloworld", so Haxe will be looking for a file called "helloworld/Main.hx" in your "src/" directory.
However you have "src/Main.hx", not "src/helloworld/Main.hx". Create a subfolder called "helloworld", move "Main.hx" in there and you will be fine. The package you use in Haxe must match the directory structure.
Make sure your package aligns with your folders, and your file name with your class name. And all of these should be inside one of your "-cp" class path folders.
For your example above, the code looks fine, I would expect your layout to look like:
build.hxml <-- build file
src/helloworld/Main.hx <-- classpath/package/class.Hx
bin/ <-- output folder
bin/HelloWorld.js <-- will be created once it compiles
And then you'd run haxe build.hxml. If that doesn't work for you please post the exact file structure of your project (which folders and which directories), and the command you use to build it, and the output.
Hope that helps,
Related
My build.hxml file looks like this:
-main Main
-cp src
-js bin/index.js
I use js.Browser in Main class. When I try to build it with F8, FlashDevelop gives me "You cannot access the js package while targeting cross". And I actually see that it tries to run:
Running process: bla-bla-bla -target "js"
...
cmd: cmd /c haxe build.hxml
haxe -cp src -main Main
So it removes -js parameter from hxml and then fails the build. How to fix it?
In the project properties, choose "Custom Build" as compilation target.
The reason is that the hxml target uses a custom build command (Build tab) and when the Application compilation target is selected, FD will try to compile it a second time with an incorrect configuration. This is legitimately a bug in FD - raise an issue on Github?
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?
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
I'm trying to compile haxe in sublime text 3 but I always get the error:
[Errno 2] No such file or directory: 'haxe'
[cmd: ['haxe', 'build.hxml']]
[dir: /home/bob/Desktop]
[path: /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/bob/.local/bin:/home/bob/bin]
[Finished]
I'm running fedora 22 and have the Haxe tar extracted in my home folder and I also Ctrl+Shift+P and installed haxelib and Haxe packages. My two files are heloWorld.hx
class HelloWorld {
static public function main() {
trace("Hello World");
}
}
and a build.hxml generated:
# Autogenerated build.hxml
# hellowWorld (js:hellowworld.js)
-main hellowWorld
js hellowworld.js
Why isn't haxe a build system option or it not compiling at all?
I found out I needed to add the haxe exacutables to /usr/bin/ because it is where paths are commonly looked for on linux. Another problem that occurs is that no matter if the class name is lower case or not I get the error:
Error: Could not process argument haxe -main HelloWorld
Class name must start with uppercase character
Build failed
~/groovy
% tree
.
├── lib
│ ├── GTemplate.class
│ └── GTemplate.groovy
└── Simple.groovy
class GTemplate {
static def toHtml() {
this.newInstance().toHtml1()
}
def toHtml1() {
"test"
}
}
import lib.*
class Simple extends GTemplate {
}
Error:
% groovyc Simple.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: Compilation incomplete: expected to find the class
lib.GTemplate in /home/bhaarat/groovy/lib/GTemplate.groovy, but the
file contains the classes: GTemplate 1 error
It looks like you are confusing Groovy with PHP-like techniques.
Because it's closer to Java, if a class exists within a subfolder, it needs to exist within a package of the same name. In your example, you could add this line to the top of GTemplate.groovy and recompile the file:
package lib
However, this means that the fully-qualified name for GTemplate is now actually lib.GTemplate. This may not be what you want.
Alternatively, if you want to use the files from a subfolder without using packages, you could remove the import statement from Simple.groovy, and instead compile and run the class like so:
groovyc -classpath $CLASSPATH:./lib/ Simple.groovy
groovy -classpath $CLASSPATH:./lib/ Simple
NOTE: If you don't have a CLASSPATH already set, you can simply use:
groovyc -classpath ./lib/ Simple.groovy
groovy -classpath ./lib/ Simple
Also, for windows machines, change $CLASSPATH: to %CLASSPATH%;
I strongly recommend learning about packages and understanding how they work. Look at this Wikipedia article on Java packages for a starting point.
I would like to build all .c files in a subdirectory. I figured I would do something like this:
src/foo/SConscript contains:
import glob;
here = Dir('.');
sourcefiles_raw = glob.glob(here.path+'/*.c');
print(sourcefiles_raw);
# print them for debugging
# ... then build them (in the process, making scons aware of dependencies)
src/SConscript contains:
SConscript(['foo/SConscript']);
SConstruct contains:
SConscript(['src/SConscript'],build_dir='build');
But it prints [], since glob.glob() runs in the directory build/foo before scons can decide which sourcefiles need to be copied from src/foo to build/foo.
How can I solve this problem?
never mind, it seems you're supposed to (RTFM) and use scons's Glob() rather than glob.glob().