Change Haxe/Kha Compile Target to C++?

I created a Haxe trait for one of my objects to test localhost network connection, but for this to work, I need it compiled for C++ (seems by default it gets compiled for JS).

I’ve searched everywhere and I can’t find any way to fix this - how do you do this?

Here is my trait .hx:

package arm;
import sys.net.Socket;
import sys.thread.Thread;

class NetworkTrait extends iron.Trait {
	static var mClient = new sys.net.Socket();
	var mReadThread:Thread;

	public function new() {
		super();

		mClient.connect(new sys.net.Host("localhost"), 3001);

		mClient.write("Hello, I'm Armory!");

		mReadThread = Thread.create(netWork);
	}

	static function netWork() {
		while(true) {
			mClient.write("I'm waiting your talk!");
			mClient.waitForRead();
			var msg = mClient.read();
			trace(msg);
		}
	}
}

And the error:

You cannot access the sys package while targeting js (for sys.net.Socket)

Hi,

You cannot compile to C++, but can compile to Hash Link C to get near native performance.

Here’s how to do it for windows: https://github.com/armory3d/armory/wiki/windows#hashlink-c

Will that get rid of my error and allow me to open a TCP socket?

Ok, so I tried to publish using Hash Link C, but I get a ton of linker errors when I try to run. How can I fix this?

Yes, it will get rid of the error. Also, maybe check out hxWebsockets, it may be helpful for you.

Btw, if you want to write code for multiple targets you can use Haxe’s conditional compilation to “guard” code against usage in wrong targets. For example, you can wrap sys code in #if sys, or Krom-related code in #if kha_krom.

They were probably introduced in the 22.10 SDK and unfortunately we haven’t yet found the reason for it (including you there are three people that can reproduce it, so it doesn’t look like it’s related to your project). For now, you should probably revert to 22.09 where things should still work normally :slight_smile:

1 Like

I rolled back to 22.09 and I no longer get linker errors when I press the “Build” button in the Armory Exporter. However, when I click “Play” in the Armory Player, I still get an error saying I’m trying to compile to JS. Is this because my runtime is set to Krom? The only other runtime option is browser and I don’t want that.

Why does Armory think I’m trying to target JS?

The “Play” button indeed only works with Krom and html5 since those have fast iteration speeds (=rebuilding doesn’t take long). Krom for example was originally meant to be a debug target whereas HL (or C++ when it still existed) was meant for final builds.

To run HL/C builds, you need to publish them with the “Publish” button. As you can see in the bottom right of your screenshot, Armory provides some Visual Studio utilities that allow you to automatically compile and run the game after publishing, for example. However, note that Hashlink/C builds may take some time to compile (still faster than the old C++ target though).

I tried to publish, but it seems my 22.09 SDK is missing the kinkmake tool. How can I install this?

Update to 2022.10. kincmake was migrated to kmake. See here:

It’s not just that Kincmake was replaced with Kmake, but vswhere.exe that is used to find installed versions of Visual Studio is no longer included in the Armory SDK because of this.

This was indeed fixed in SDK 2022.10, but since you already downgraded to 2022.09 for being able to build HL projects you should either open the project in Visual Studio manually or you need to implement this little untested (!) workaround:

Open <SDK_PATH>/armory/blender/arm/utils.py in a text editor and replace line 1141

    path_file = os.path.join(get_sdk_path(), 'Kha', 'Kinc', 'Tools', 'kincmake', 'Data', 'windows', 'vswhere.exe')

with

    path_file = os.path.join(os.environ["ProgramFiles(x86)"], 'Microsoft Visual Studio', 'Installer', 'vswhere.exe')

(don’t forget the 4 spaces before the actual line of code!)

Then save the file and restart Blender.

Sorry for all these inconveniences, normally, working with Armory should be smoother :slight_smile:

1 Like

Thanks, I’ll see if I can get it working later. Yeah, it has been non-stop yikes moments trying to get Armory3D up and running. Regardless, I’m still super excited to use it to make a realistic flight simulator :smile:

1 Like