COMMUNITY

Add my own lib

Hello, community,

maybe a rather beginner’s question, but is there a possibility to attach your own libs in Haxe?

example: I have written a calculator in C++ and in Java and don’t want to rewrite it completely in Haxe. But I want to use the function “Add(x,y)” in my Haxe code.

Is it possible to include the calculator as a library depending on the compiler.

Unfortunately I have not found any beginner-friendly guides for this.

Greetings

For Java, you can just include a .jar in compilation via --java-lib. For C++… it might be quicker to rewrite it in Haxe rather than trying to figure out how C++ externs work, depending on how much code we’re talking about and how familiar you are with C++. :smiley: Plus, it would work on targets other than Java and C++ then.

1 Like

First of all, thank you very much,

for my work I will probably have to find out how it works with the C++ libs …

Does anyone have any helpful links to get started ?

For C++ you can check haxe.Int64 as an example of interoperation:


AFAIK @:include generates respective instruction in the compiled c++ code.
@:native specifies for the Haxe compiler which name to generate for a symbol instead of its haxe name.

1 Like

Thank you for the example that has explained a lot.

I have another question about the directory structure:

The Int64.h has been added by installing hxcpp via haxelib and can be found at :

…HaxeToolkit\haxe\lib\hxcpp"version"\include\cpp\Int64.h

Is then used in the code by

called.

Where exactly would I store my Addieren.h to call it up in a Main.hx?
In :

haxe\lib\hxcpp"version"\include\calculator\Add.h

I guess you need to add the directory with your lib to include paths for hxcpp build tool somehow.
Maybe you can find a hint here: https://github.com/HaxeFoundation/hxcpp/blob/master/toolchain/linux-toolchain.xml#L56

The easiest way probably would be to just put your lib into /path/to/hxcpp/include/, but that seems to be a dirty workaround :slight_smile:

Hello, thank you, I will definitely take a look at that.

After some searching I found this:
http://old.haxe.org/doc/cpp/ffi

Not exactly what I was looking for but it’s a start. I will take a closer look at how promising this approach is.
Greetings

AFAIK it’s an outdated approach.