I am making this in haxe, just wanted to try something and compile the Haxe code by using HXCPP. I got linker errors on github.
This is the code.
package;
class Main
{
public static function main()
{
trace("havaliyim");
}
}
And here is the error:
Error
Is this happens because i used windows-2022 on workflow?
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
I've been trying to use Haxe to generate C# code that calls methods from a dll written in C++/CLR. This dll is called "AudioClientSDK.dll"
Here is an example of the Haxe code I'm trying:
package hello;
class HelloWorld {
static public function main():Void {
var s = untyped __cs__("AudioClientCLR.AudioClientAPI.release()");
}
}
As you can see I'm using "Haxe magic" syntax (I previously tried Haxe extern classes that resulted pretty much in the same problems) to directly call the release method within the AudioClientSDK.dll. The method signature inside the dll is:
public : void AudioClientCLR::AudioClientAPI::release()
However, when I try to compile this code, Haxe throws this error:
haxe -cp src -cs out/CS -main hello.HelloWorld
haxelib run hxcs hxcs_build.txt --haxe-version 3103
c:\git\HelloHaxe\src\hello\HelloWorld.hx(6,16): error CS0103: The name
'AudioClientCLR' does not exist in the current context
Compilation error
Native compilation failed
Error: Build failed
If I try to pass the AudioClientSDK.dll reference as -net-lib or -net-std I get these errors:
haxe -cp src -cs out/CS -net-lib lib/CPP/x86/AudioClientSDK.dll -main hello.HelloWorld
File "ilMetaReader.ml", line 281, characters 36-42: Assertion failed
error 0x2
haxe -cp src -cs out/CS -net-std lib/CPP/x86/AudioClientSDK.dll -main hello.HelloWorld
Error: No .NET std lib directory with the pattern 'net-20' was found in the -net-std search path. Try updating the hxcs lib to the latest version, or specifying another -net-std path.
Do any of you know how to correctly use the dll?
Thanks in advance.
P.S. These are some properties of the AudioClientSDK.dll:
Targeted framework: .NETFramework,Version=v4.0
Platform: Win32
Platform Toolset: VisualStudio 2010 (v100)
Use of MFC: Use MFC in a Shared DLL
Common Language Runtime: Common Language Runtime Support (/clr)
Also, please note that this dll can be used without problems from C# in Visual Studio.
This seems like a bug. Please report it ASAP to the haxe issue list, with a downloadable link to the offending dll, and it might get included inyo the 3.2 final release
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,
I am new in ndk development in android.I have gone through the file system of ndk android.
Here, explaining what i have done.
1) i have created a folder named "jni" then create 2 file named Android.mk and ndkfoo.c.
In Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := ndkfoo
LOCAL_SRC_FILES := ndkfoo.c
include $(BUILD_SHARED_LIBRARY)
and in ndkfoo.c
#include <string.h>
#include <jni.h>
jstring Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
return (*env)->NewStringUTF(env, "Hello from native code!");
}
then i have created NdkFooActivity class, in which i have written
// load the library - name matches jni/Android.mk
static {
System.loadLibrary("ndkfoo");
}
But now when i build from cygwin in xp it creates .so file successfully then i run as android application. It gives me java.lang.UnsatisfiedLinkError in LOGCAT.
So, Please let me know where i am wrong.
Thanks in Advance,
I think you forgot to change the package name.
Java_com_mindtherobot_samples_ndkfoo
It should be your package what you have specified creating project.
Also(just ran into this issue), please note that System.loadLibrary() will always throw an exception if you are testing on the Intel Atom x86 emulator. It works just fine on regular Android emulators and debugging on a physical device.
Although this has not been the OP's problem, I had the same java.lang.UnsatisfiedLinkError because of missing
static {
System.loadLibrary("mylibraryname");
}
There's a good chance the signature is wrong, as others have mentioned.
If you run the javah utility, you can find the exact signature. From the bin folder in your project, where the .apk is and the root of the Java class hierarchy is generated, run:
javah -o jni_sig.h com.mindtherobot.whatever.your.package.is.NdkFooActivity
...and, if you got the package name and class name correct, it will write out a header (called jni_sig.h) with the correct function signature(s) for any native functions. Copy that to your header and .c file, adding parameters as needed, and it should work correctly.
Maybe not relevant anymore but as far as I know you also need to add the "lib" prefix to your native library name. In your case you need to change the Android.mk to
"LOCAL_MODULE := libndkfoo" and keep "System.loadLibrary("ndkfoo");" as it is. Check the ndk sample code.
I'm pretty sure that should be:
JNIEXPORT jstring JNICALL Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
return (*env)->NewStringUTF(env, "Hello from native code!");
}
Which SDK are you targeting and which version of the NDK do you have? Does the error you're getting say that it couldn't load the library at all or that there was an unimplemented method? Either way make sure you don't have android:hasCode="false" set on the application tag in your manifest.
You can also open up the APK file after a build using winrar or something similar to make sure that the libndkfoo.so file is actually being included with the package.
Either way if you aren't declaring the native function in NdkFooActivity you will get that error, i.e.
public static native String invokeNativeFunction();
JNIEXPORT jstring JNICALL Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
return (*env)->NewStringUTF(env, "Hello from native code!");
}
the problem is that you compile for a target processor and execute in other. if you compile in ARM(armeabi) then execute in armeabi based emulator.
create a file called application.mk in same folder as Android.mk and put inside it one of this:
APP_ABI := x86
APP_ABI := armeabi
APP_ABI := mips
APP_ABI := armeabi x86 mips //to compile in all target and you will get 3 *.so files
then compile->run.
it should work.
Create a file Application.mk in jni folder.Copy following line and paste it to Application.mk and save.Now build the project with your cgywin and run again
APP_ABI := armeabi armeabi-v7a
The method name Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction
may be not same as that of your package name or class name.
To make this naming of method exactly same you must use javah.
This will make a header file which will be having the same method name that is required.To make this header file go to the classes folder in the bin of your project(make sure you have created the java file with static method and build it properly) by this command in your terminal
~/workspace/Android_Example2/bin/classes$
In this directory write the following command
sudo javah -jni com.NDK.android_example2.MainActivity
Change the package name and class name according to your project.This will create a com_NDK_android_example2_MainActivity.h in your classes folder.
Simply move this file into your jni folder. In this file, there will be static methods that you have created in the MainActivity.java file but they are just declared not implemented that you will implement in your C file.
NOTE: While Coping the method check that the method parameters are need to be declared, so make them declare in your C file.
Hope this help.
Replace this
Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction
With
Java_your_packege_name_your_Activity_Name_invokeNativeFunction
Example if your package is com.pack and Activity Name name is MainActivity then
Java_com_pack1_MainActivity_invokeNativeFunction
Don't forget to add reference in Activity.
// load the library - name matches jni/Android.mk
static {
System.loadLibrary("ndkfoo");
}
public native String invokeNativeFunction();
Repeat all these step it should work :)
I also had a java.lang.UnsatisfiedLinkError error. I verified everything mention in above answers but was still getting the error. I eventually discovered that the JNI method names cannot have underscores.
Example:
Java_com_example_app_NativeLib_print_out_stuff <- generates java.lang.UnsatisfiedLinkError: print_out_stuff
Rename the print_out_stuff function to something without underscores:
Java_com_example_app_NativeLib_printOutStuff <- works
here's a tutorial how to use native code: here
make sure you dont have any spaces in your project path.
also you cant use an underscore in your package or project name.