<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>day26 — Gerrit Niezen</title>
    <link>https://gerritniezen.com/tag:day26</link>
    <description>Maker of open-source software and hardware.</description>
    <pubDate>Fri, 20 Nov 2026 21:51:19 +0000</pubDate>
    <image>
      <url>https://i.snap.as/aMPXpIot.png</url>
      <title>day26 — Gerrit Niezen</title>
      <link>https://gerritniezen.com/tag:day26</link>
    </image>
    <item>
      <title>Attempting to get libmtp compiled on Windows</title>
      <link>https://gerritniezen.com/attempting-to-get-libmtp-compiled-on-windows?pk_campaign=rss-feed</link>
      <description>A couple of days ago I mentioned that I&#39;m attempting to compile libmtp under MSYS2/MINGW64. Steps so far: Install MSYS2 Do pacman -Syuu r...</description>
      <content:encoded><![CDATA[<p><a href="https://gerritniezen.com/a-cross-platform-approach-to-accessing-android-devices-over-usb">A couple of days ago</a> I mentioned that I&#39;m attempting to compile <code>libmtp</code> under MSYS2/MINGW64. Steps so far:</p>
<ul><li>Install <a href="https://www.msys2.org/">MSYS2</a></li>
<li>Do <code>pacman -Syuu</code> repeatedly after first start until everything is up to date</li>
<li>Install git: <code>pacman -S git</code></li>
<li>Install <code>base-devel</code> for basic development utilities</li>
<li>install <code>mingw-w64-x86_64-toolchain</code> (as we need   <code>mingw-w64-x86_64-gcc</code> to not get <code>_spawnv</code> errors, see <a href="https://github.com/libimobiledevice/libplist/issues/136">https://github.com/libimobiledevice/libplist/issues/136</a>)</li>
<li>Install <code>mingw-w64-x86_64-libiconv</code></li>
<li>Install <code>mingw-w64-x86_64-libusb</code></li>
<li>Remember to run <code>autogen.sh</code> before running <code>./configure</code></li>
<li>Run <code>make</code></li></ul>

<p>Some useful MSYS2-specific things:</p>
<ul><li>Use <code>cd /c/</code> to get to the C: drive</li>
<li><code>pacman -S</code> to install, <code>-R</code> to remove and <code>-Ss</code> to search</li>
<li>To access Windows path (e.g. to run node/npm, which can&#39;t be installed in MSYS2), add <code>-use-full-path</code> to the mingw64 app shortcut, or set environment variable <code>MSYS2_PATH_TYPE</code> to <code>inherit</code></li></ul>

<p>Now, after all of this I still got the following error:</p>

<pre><code>unicode.c: In function &#39;utf16_to_utf8&#39;:
unicode.c:91:23: error: &#39;PTPParams&#39; {aka &#39;struct _PTPParams&#39;} has no member named &#39;cd_ucs2_to_locale&#39;
   91 |   nconv = iconv(params-&gt;cd_ucs2_to_locale, &amp;stringp, &amp;convlen, &amp;locp, &amp;convmax);
      |                       ^~
unicode.c: In function &#39;utf8_to_utf16&#39;:
unicode.c:126:23: error: &#39;PTPParams&#39; {aka &#39;struct _PTPParams&#39;} has no member named &#39;cd_locale_to_ucs2&#39;
  126 |   nconv = iconv(params-&gt;cd_locale_to_ucs2, &amp;stringp, &amp;convlen, &amp;unip, &amp;convmax);
</code></pre>

<p>Turns out, <a href="https://github.com/libmtp/libmtp/issues/20">it&#39;s a known issue</a>. Based on a potential fix linked to in that GitHub issue, I was able to write a fix for a different file:</p>

<pre><code>diff --git a/src/unicode.c b/src/unicode.c
index 2adc94e..b14274b 100644
--- a/src/unicode.c
+++ b/src/unicode.c
@@ -87,12 +87,14 @@ char *utf16_to_utf8(LIBMTP_mtpdevice_t *device, const uint16_t *unicstr)
   size_t convmax = STRING_BUFFER_LENGTH*3;

   loclstr[0]=&#39;\0&#39;;
+  #if defined(HAVE_ICONV) &amp;&amp; defined(HAVE_LANGINFO_H)
   /* Do the conversion.  */
   nconv = iconv(params-&gt;cd_ucs2_to_locale, &amp;stringp, &amp;convlen, &amp;locp, &amp;convmax);
   if (nconv == (size_t) -1) {
     // Return partial string anyway.
     *locp = &#39;\0&#39;;
   }
+  #endif
   loclstr[STRING_BUFFER_LENGTH*3] = &#39;\0&#39;;
   // Strip off any BOM, it&#39;s totally useless...
   if ((uint8_t) loclstr[0] == 0xEFU &amp;&amp; (uint8_t) loclstr[1] == 0xBBU &amp;&amp; (uint8_t) loclstr[2] == 0xBFU) {
@@ -121,7 +123,7 @@ uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t *device, const char *localstr)

   unicstr[0]=&#39;\0&#39;;
   unicstr[1]=&#39;\0&#39;;
-
+  #if defined(HAVE_ICONV) &amp;&amp; defined(HAVE_LANGINFO_H)
   /* Do the conversion.  */
   nconv = iconv(params-&gt;cd_locale_to_ucs2, &amp;stringp, &amp;convlen, &amp;unip, &amp;convmax);

@@ -130,6 +132,7 @@ uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t *device, const char *localstr)
     unip[0] = &#39;\0&#39;;
     unip[1] = &#39;\0&#39;;
   }
+  #endif
   // make sure the string is null terminated
   unicstr[STRING_BUFFER_LENGTH*2] = &#39;\0&#39;;
   unicstr[STRING_BUFFER_LENGTH*2+1] = &#39;\0&#39;;
</code></pre>

<p>Lo and behold, I got it to compile!</p>

<hr/>

<p>I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting <a href="https://100daystooffload.com">https://100daystooffload.com</a>.</p>

<p><a href="https://gerritniezen.com/tag:100DaysToOffload" class="hashtag"><span>#</span><span class="p-category">100DaysToOffload</span></a> <a href="https://gerritniezen.com/tag:day26" class="hashtag"><span>#</span><span class="p-category">day26</span></a> <a href="https://gerritniezen.com/tag:libmtp" class="hashtag"><span>#</span><span class="p-category">libmtp</span></a></p>

<p><i>Comment on this post</i>
<div id="cusdis_thread"></div></p>
]]></content:encoded>
      <guid>https://gerritniezen.com/attempting-to-get-libmtp-compiled-on-windows</guid>
      <pubDate>Thu, 21 May 2020 15:46:22 +0000</pubDate>
    </item>
  </channel>
</rss>