Create a dll via hxcpp and load it via hxcpp


So i was just playing around with something, just to see if its possible. Basically, i wanted to create a dll from haxe via hxcpp, then take said .dll and load it into another haxe program, again via hxcpp - and i fell at the first hurdle.

So, i have a “nothing program” (empty Main::main), and added -D dll_import to the build.

Firstly i get a few warnings:

haxe/lib/hxcpp/git/include\hx/Telemetry.h(33): warning C4273: '__hxcpp_gc_used_bytes': inconsistent dll linkage
haxe/lib/hxcpp/git/include\hx/GC.h(34): note: see previous definition of '__hxcpp_gc_used_bytes'

Which can be fixed by prefixing the referenced functions in Telemetry.h with HXCPP_EXTERN_CLASS_ATTRIBUTES so the signatures match.

More importantly, i get a link error:

LINK : fatal error LNK1181: cannot open input file '1.obj'

Which obviously stops the build. Anyone have any ideas about this / done this? Or what 1.obj even is?


Hi, Ian! This is very interesting theme, I’m too looking for similar stuff. But currently without success :frowning: I’ll follow this theme, maybe some ideas will be appear.

I think, here is solution for your sotuation

1 Like

Ah ha! Perfect! Thanks!

D dll_link rather than -D dll_import

Will crack on and see where i get, but so far the .dll is built and the dependency walker looks ok.


(Not sure how to mark a post as “solution”)

So i think dll_import might be needed after all, if you look at the the hxcpp Math_obj decl:

class HXCPP_EXTERN_CLASS_ATTRIBUTES Math_obj : public hx::Object

compared with my test:

class HXCPP_CLASS_ATTRIBUTES Main_obj : public hx::Object

(missing the _EXTERN_ part which presumably is a __declspec(dllimport) type #define)

Which is why dependency walker is showing haxe related classes in the output .dll but not mine. So i think the original question applies.

Follow up: So i guess the question is really, are the files “hxMath.h” and “Math.cpp” handwritten? Or generated? If they are generated, how? I assumed they were generated, but looking a little deeper im not so convinced now.

@ianharrigan, were you able to reference a dll in the end?

I’m fairly sure I’m able to import a static library (.lib) file via build.xml when building my native extension, but I’ve yet to have success referencing it’s respective dynamic (.dll) library.

IIRC correctly i didnt get anywhere with this. It was just a playaround so i didnt spend that much time on it… however, if you can share a project (demo) of creating a .lib and/or dll and consuming that lib from an external c++ app that sounds pretty useful… I might have another play around when i get a spare few hours…

Would be useful to be able to create .libs + .dlls built in haxe an consumed from non-haxe client applications.