<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>day26 &amp;mdash; Gerrit Niezen</title>
    <link>https://gerritniezen.com/tag:day26</link>
    <description>Maker of open-source software and hardware.</description>
    <pubDate>Thu, 30 Apr 2026 07:10:32 +0000</pubDate>
    <image>
      <url>https://i.snap.as/aMPXpIot.png</url>
      <title>day26 &amp;mdash; 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>&lt;![CDATA[A couple of days ago I mentioned that I&#39;m attempting to compile libmtp under MSYS2/MINGW64. Steps so far:&#xA;&#xA;Install MSYS2&#xA;Do pacman -Syuu repeatedly after first start until everything is up to date&#xA;Install git: pacman -S git&#xA;Install base-devel for basic development utilities&#xA;install mingw-w64-x8664-toolchain (as we need   mingw-w64-x8664-gcc to not get spawnv errors, see https://github.com/libimobiledevice/libplist/issues/136)&#xA;Install mingw-w64-x8664-libiconv&#xA;Install mingw-w64-x8664-libusb&#xA;Remember to run autogen.sh before running ./configure&#xA;Run make&#xA;&#xA;Some useful MSYS2-specific things:&#xA;&#xA;Use cd /c/ to get to the C: drive&#xA;pacman -S to install, -R to remove and -Ss to search&#xA;To access Windows path (e.g. to run node/npm, which can&#39;t be installed in MSYS2), add -use-full-path to the mingw64 app shortcut, or set environment variable MSYS2PATHTYPE to inherit&#xA;&#xA;Now, after all of this I still got the following error:&#xA;&#xA;unicode.c: In function &#39;utf16toutf8&#39;:&#xA;unicode.c:91:23: error: &#39;PTPParams&#39; {aka &#39;struct PTPParams&#39;} has no member named &#39;cducs2tolocale&#39;&#xA;   91 |   nconv = iconv(params-  cducs2tolocale, &amp;stringp, &amp;convlen, &amp;locp, &amp;convmax);&#xA;      |                       ^~&#xA;unicode.c: In function &#39;utf8toutf16&#39;:&#xA;unicode.c:126:23: error: &#39;PTPParams&#39; {aka &#39;struct PTPParams&#39;} has no member named &#39;cdlocaletoucs2&#39;&#xA;  126 |   nconv = iconv(params-  cdlocaletoucs2, &amp;stringp, &amp;convlen, &amp;unip, &amp;convmax);&#xA;&#xA;Turns out, it&#39;s a known issue. Based on a potential fix linked to in that GitHub issue, I was able to write a fix for a different file:&#xA;&#xA;diff --git a/src/unicode.c b/src/unicode.c&#xA;index 2adc94e..b14274b 100644&#xA;--- a/src/unicode.c&#xA;+++ b/src/unicode.c&#xA;@@ -87,12 +87,14 @@ char utf16toutf8(LIBMTPmtpdevicet device, const uint16t unicstr)&#xA;   sizet convmax = STRINGBUFFERLENGTH3;&#xA;&#xA;   loclstr[0]=&#39;\0&#39;;&#xA;if defined(HAVEICONV) &amp;&amp; defined(HAVELANGINFOH)&#xA;   / Do the conversion.  /&#xA;   nconv = iconv(params-  cducs2tolocale, &amp;stringp, &amp;convlen, &amp;locp, &amp;convmax);&#xA;   if (nconv == (sizet) -1) {&#xA;     // Return partial string anyway.&#xA;     locp = &#39;\0&#39;;&#xA;   }&#xA;endif&#xA;   loclstr[STRINGBUFFERLENGTH3] = &#39;\0&#39;;&#xA;   // Strip off any BOM, it&#39;s totally useless...&#xA;   if ((uint8t) loclstr[0] == 0xEFU &amp;&amp; (uint8t) loclstr[1] == 0xBBU &amp;&amp; (uint8t) loclstr[2] == 0xBFU) {&#xA;@@ -121,7 +123,7 @@ uint16t utf8toutf16(LIBMTPmtpdevicet device, const char localstr)&#xA;&#xA;   unicstr[0]=&#39;\0&#39;;&#xA;   unicstr[1]=&#39;\0&#39;;&#xA;if defined(HAVEICONV) &amp;&amp; defined(HAVELANGINFOH)&#xA;   / Do the conversion.  /&#xA;   nconv = iconv(params-  cdlocaletoucs2, &amp;stringp, &amp;convlen, &amp;unip, &amp;convmax);&#xA;&#xA;@@ -130,6 +132,7 @@ uint16t utf8toutf16(LIBMTPmtpdevicet device, const char localstr)&#xA;     unip[0] = &#39;\0&#39;;&#xA;     unip[1] = &#39;\0&#39;;&#xA;   }&#xA;endif&#xA;   // make sure the string is null terminated&#xA;   unicstr[STRINGBUFFERLENGTH2] = &#39;\0&#39;;&#xA;   unicstr[STRINGBUFFERLENGTH2+1] = &#39;\0&#39;;&#xA;&#xA;Lo and behold, I got it to compile!&#xA;&#xA;---&#xA;I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.&#xA;&#xA;#100DaysToOffload #day26 #libmtp&#xA;&#xA;iComment on this post/i&#xD;&#xA;div id=&#34;cusdisthread&#34;/div]]&gt;</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" 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>