snowkit / linc

A collection of Haxe native libraries for hxcpp. SDL, OpenGL, OpenAL and more.
http://snowkit.github.io/linc/
23 stars 2 forks source link

libstem_gamepad library #7

Open BluShine opened 8 years ago

BluShine commented 8 years ago

Hello, I'm trying to write a linc lib for libstem_gamepad because most of the current haxe gamepad libraries are somewhat lacking. I downloaded the linc empty project and got it all set-up, then renamed everything. But I'm having some trouble when it comes actually interacting with the C library. This is my first time trying to do any extern stuff in haxe, so I've probably made some stupid newbie mistakes. Would someone mind taking a quick look at it and telling me what I'm doing wrong? Repo is at https://github.com/BluShine/linc_stempad Here's some of the errors I'm getting when I try to compile build.hxml

Creating library Test.lib and object Test.exp
fd282d4a_Test.obj : error LNK2019: unresolved external symbol _Gamepad_init referenced in function "public: static class null __cdecl Test_obj::main(void)" (?main@Test_obj@@SA?AVnull@@XZ)
fd282d4a_Test.obj : error LNK2019: unresolved external symbol _Gamepad_shutdown referenced in function "public: static class null __cdecl Test_obj::main(void)" (?main@Test_obj@@SA?AVnull@@XZ)
fd282d4a_Test.obj : error LNK2019: unresolved external symbol _Gamepad_numDevices referenced in function "public: static class null __cdecl Test_obj::main(void)" (?main@Test_obj@@SA?AVnull@@XZ)
Test.exe : fatal error LNK1120: 3 unresolved externals
ruby0x1 commented 8 years ago

Hi!

Your setup looks almost correct. You include files.xml which brings the <files id="native-libstem"> definition - but you aren't using that definition anywhere yet. You have to reference it in a target.

When you create a files node in hxcpp xml, you are only defining it (or adding to a previously defined one). It will need to be referenced in a target node. The haxe files and target are defined by hxcpp internally. The haxe files node is where your haxe cpp code gets added, and you are adding to it in the xml. Then, the haxe target gets run - which tells the build tool what files to build. For the haxe target it already references the haxe files since they are internal, for external files nodes you need to tell it to add them.

So in this case, it seems you are just missing the <files id="native-libstem"/> reference inside the <target='haxe'> part.

<target id="haxe">

        <!-- add linker flags to the haxe build output -->

        <!-- reference the files in the haxe target so they get included -->
        <files id="native-libstem"/>

</target>

Hope that helps

BluShine commented 8 years ago

Thanks a ton, that worked perfectly. I've got most of the library working, but I'm having trouble with callback functions. Do you have any advice, or know of any similar implementations that I could look at? I did a quick search on google and looked through a few of the linc projects, but couldn't seem to find anything that worked for me.

On the C++ side, I'm got functions like this:

void Gamepad_deviceAttachFunc(void (* callback)(struct Gamepad_device * device, void * context), void * context);

And I've tried a few different ways of passing in haxe functions, but couldn't get anything that compiled. Is there a standard "linc way" of handling this kind of thing? Or would it make more sense to just hide it in a helper function?

Anyways, thanks again for the help.

ruby0x1 commented 8 years ago

I wouldn't say a standard way but here's some suggestions in the mean time.

ruby0x1 commented 7 years ago

Hey @BluShine how is your adventure going?