<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kier&#039;s Blog &#187; mingw</title>
	<atom:link href="http://www.kierdugan.com/tag/mingw/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kierdugan.com</link>
	<description>Damn right.</description>
	<lastBuildDate>Fri, 11 Mar 2011 23:36:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bashing Windows</title>
		<link>http://www.kierdugan.com/2010/03/23/bashing-windows/</link>
		<comments>http://www.kierdugan.com/2010/03/23/bashing-windows/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 19:17:42 +0000</pubDate>
		<dc:creator>Kier</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[DLL]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[mingw]]></category>
		<category><![CDATA[msvc]]></category>
		<category><![CDATA[pexports]]></category>

		<guid isPermaLink="false">http://www.kierdugan.com/?p=40</guid>
		<description><![CDATA[I seem to blog the most about needing to blog more often. Unfortunately for me, interesting things don&#8217;t happen often.<a href="http://www.kierdugan.com/2010/03/23/bashing-windows/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>I seem to blog the most about needing to blog more often. Unfortunately for me, interesting things don&#8217;t happen often. So instead of waiting for something cool to happen, I&#8217;m just going to blog about the little things and hope for the best.</p>
<p>I drafted a post about my adventures with trying to compile some open source software, but it turned out far too long and it didn&#8217;t actually concentrate on the point I was trying to make. So instead I&#8217;ll jump right to it.</p>
<p>Yesterday I decided, randomly, to have a look at <a href="http://curl.haxx.se/libcurl/" target="_blank">libcurl</a>. It&#8217;s a surprisingly powerful library for C that supports a huge amount of internet protocols with only a few function calls. The code examples on the website made it look easy enough to use, so I thought I&#8217;d download it and see what I can do with it. Unfortunately compiling it myself turned out to be annoyingly difficult, so I just downloaded the binaries. Naturally these were all in MinGW form and I needed them them to be MSVC compatible.</p>
<p>After some googling I found that MinGW comes with a tool called <a href="http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs" target="_blank"><font face="Courier">pexports</font></a> which dumps all the symbols of a DLL. So using that I wrote a Bash script that does this for all the DLLs in a directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;.*\.dll&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/.dll//&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    pexports <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>.dll&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>.def&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;lib /machine:i386 /def:<span style="color: #007800;">$i</span>.def&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> makelib.bat
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This creates a <font face="Courier">.def</font> file for each DLL which lists all the symbols that must be exported, and adds a line to <font face="Courier">makelib.bat</font> which will create the MSVC import library. The two pronged approach is unfortunately necessary here because the Microsoft LIB tool won&#8217;t run through the Cygwin prompt.</p>
<p>The first line might seem complicated, but it&#8217;s not too bad. <font face="Courier">ls</font> lists all the files in the current directory, <font face="Courier">grep</font> then singles out all the <font face="Courier">.dll</font> files, and finally <font face="Courier">sed</font> removes the trailing <font face="Courier">.dll</font>. In the loop itself <font face="Courier">$i</font> will therefore always be of the form &#8220;<font face="Courier">&lt;mydll&gt;</font>&#8221; instead of &#8220;<font face="Courier">&lt;mydll&gt;.dll</font>&#8220;.</p>
<p>I&#8217;m no expert with Bash scripting so there&#8217;s probably an easier way to do it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kierdugan.com/2010/03/23/bashing-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

