haxiomic / haxe-c-bridge

Easily interact with haxe classes from C with an automatically generated C header
MIT License
51 stars 5 forks source link

Trying to get this working with Unreal Engine : MT / MD mismatch? #37

Closed datee closed 2 years ago

datee commented 2 years ago

So - the haxe-c-bridge sounds really awesome. I would love to add lib or dll files built from Haxe to use in Unreal Engine. For now i am experimenting a bit here - trying to build a .lib file (win64) to do just that.

But im stuck here with this build error in Unreal when adding the .h and .lib file from the haxe-c-bridge output: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'

Guess there is a mismatch with MT / MD here. Havent found a good way to make it work yet - Unreal wont accept MT it seems and Haxe-C-Bridge / hxcpp complains when i try to set /MD.

Any good suggestions on how to approach this?

haxiomic commented 2 years ago

Interesting! It would be great to get this working

What are you hxml arguments used to compile the .lib? Or better yet, a zip of your project – I can try to have a play here

I'm a newbie to UE, how are you adding the .lib and .h? Is it via Visual Studio or is it through some UE engine interface?

Do you intend for it to be a static lib or a dynamic one (or just whichever works?)

datee commented 2 years ago

Cool! It would be so awesome to get this to work!

After what i've learned it doesnt seem to be possible to include a .lib file thats using /MT , it needs to be /MD. But im not sure of how haxe-c-bridge can generate a lib using /MD.. is it possible?

I have made a little test project for you, that has the simplest setup of haxe-c-bridge and a UnrealEnigne 4.27 project set up to include the .lib file. Its basicly the same as your example but wrapped in a c++ Blueprint Library in unreal engine. The unreal\TestHaxeC\Source\TestHaxeC\ folder has a copy of the generated .h file thats being included in unreal\TestHaxeC\Source\TestHaxeC\TestBPFL.cpp (The blueprint library class).

In the file TestHaxeC.Build.csin the same folder the .lib file is linked up (you need to change the path) and the .lib file itself is in the folder unreal\TestHaxeC\Binaries\Win64\

https://www.dropbox.com/t/1Zfmtfe13n1GQkeD

It could ofcourse also be linked using a .dll dynamicly , but then you still need to include a .lib file in addition to the .h, right?

haxiomic commented 2 years ago

Thanks for this :), I'll visit this over the weekend I expect we'll need to look into how hxcpp uses mscv to make sure we can control that switch, but can't see why it couldn't work at this point

datee commented 2 years ago

Nice. πŸ‘Œ Excited to see how it goes 😎

haxiomic commented 2 years ago

So it looks like you can add -D ABI=-MD and hxcpp will use that instead of -MT https://github.com/HaxeFoundation/hxcpp/blob/master/toolchain/msvc-toolchain.xml#L15

This generated a .lib for me without error, presumably now linked as UE likes it but I haven't tested (it's a busy weekend)

Fingers crossed that works for you!

(be sure to delete your bin/ first! And add -D HXCPP_VERBOSE so you can see all the cl.exe commands and verify)

datee commented 2 years ago

Aha! Yey! Great success!! Thanks so much for the help with this! Now, with MD i'm able to link the .lib file and run the haxe code in unreal !! It actually works fine!! :)

This is fantastic, it will open many new possibilites! With some bindings and glue it should be possible to do a lot of things here :)

haxiomic commented 2 years ago

Yey, that’s awesome :D, very keen to hear what you create!

keep us posted on the haxe community forum

datee commented 2 years ago

Will do! πŸ‘πŸ˜Ž