Getting a Node.js library using libmtp working on Windows
While compiling the Node.js native module, I got the following error:
Macro definition of snprintf conflicts with Standard Library function declaration
Searching StackOverflow led to this solution, which I added to the libmtp source code:
#if _MSC_VER < 1900 #define snprintf _snprintf #endif
I also kept on getting a “Module not found” error, until I re-read my own post and used Dependency Walker to figure out that for some reason my
.node file is looking for
libmtp-9.dll.dll instead of
libmtp-9.dll. 🤷♂️️ I also had to copy
libusb-1.0.dll into the same folder, as it was looking for that too.
Finally, like magic, I was able to connect to a device on Windows over MTP with my own Node.js library using libmtp, instead of the Windows MTP implementation that can only be accessed through Windows Explorer or the Windows APIs.
And I just submitted a PR to get Windows builds fixed in the upstream libmtp library.
Next step: Getting it compiled for 32-bit Windows using
I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.