Include cpp files directory in Haxe build process

643 views Asked by At

I need to include some cpp files into my haxe project, but I don't know how to tell the compiler where the directory is. I don't want to use absolute path. How can I include the directory with the cpp files?

@:include("LinearMath/btScalar.h")
@:native("::btTypedObject")
@:structAccess
@:unreflective

EDIT: Ok, i got it now.

If you want to use your own .hxcpp_config.xml, type in the console:

haxelib run hxcpp

A .hxcpp_config.xml will be created in the Users Directory (talking now about win 7).

<!-- Compiling on windows ... -->
<compiler id="MSVC" if="windows">
    <!-- Example adding a build flag -->
    <flag value = "-IC:/path/>
</compiler>

Different ways ... http://www.wighawag.com/blog/2014/12/Hxcpp-extern

2

There are 2 answers

0
mighty.marcus On

Thank you, but I know CFFI and how to compile ndlls. The @:include macros are quite new I think. There is even a @:cppFileCode and a @:functionCode macro to directly insert header code and cpp code from a .hx file. I tested it including and I was able to call SetCursorPos Windows API function from the .hx file.

This is really cool stuff. Now I'm stuck because I don't know how to add include compiler flag to build process, e.g. -Ic:mycoolstuff/path.

0
PartyGodTroy On

Haxe doesn't let your .hx files mix with c++ code, to use native code you need to use the C Foreign Function Interface (CFFI). Here is a link to the documentation. The idea is to first write your c++ code, write an interface to expose methods within that code, compile a ndll, then load your methods into haxe with the cpp.Lib.load('dllNameWithoutTheDotdll','method_signature',numberOfArguments);

Unfortunately there are not many pure CFFI examples, but you may want to check out OpenFL Native Extensions. They are basically code templates that contain a collection of interfaces (including CFFI), to access non-haxe APIs

Hope that helps and good luck!