<?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>/home/nick &#187; C/C++</title>
	<atom:link href="http://whatwouldnickdo.com/wordpress/category/cc/feed/" rel="self" type="application/rss+xml" />
	<link>http://whatwouldnickdo.com/wordpress</link>
	<description>Discussions on Programming, Linux, and whatever else.</description>
	<lastBuildDate>Sun, 22 Aug 2010 14:56:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Eclipse C/C++ and Linux Libraries</title>
		<link>http://whatwouldnickdo.com/wordpress/328/eclipse-cdt-and-linux-libraries/</link>
		<comments>http://whatwouldnickdo.com/wordpress/328/eclipse-cdt-and-linux-libraries/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 15:50:39 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=328</guid>
		<description><![CDATA[This is a really quick tutorial on configuring Eclipse CDT (C/C++ Development Tools) so you can work with shared libraries.  A lot of this may be basic for some readers, but for a programmer that&#8217;s used to Visual Studio and a Windows dll environment it may not.  Windows uses DLL (Dynamic link library) with the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a really quick tutorial on configuring <a href="http://www.eclipse.org/cdt/">Eclipse CDT</a> (C/C++ Development Tools) so you can work with <a href="http://en.wikipedia.org/wiki/Shared_library#Shared_libraries">shared libraries</a>.  A lot of this may be basic for some readers, but for a programmer that&#8217;s used to Visual Studio and a Windows dll environment it may not.  <span id="more-328"></span>Windows uses DLL (Dynamic link library) with the .dll extension.  The closest linux equivalent is the shared library which uses a .so extension.   I&#8217;m going to use <a href="http://en.wikipedia.org/wiki/Libavcodec">libavcodec.so</a> as the shared library to be used in my example.  This library is part of the <a href="http://ffmpeg.org/">ffmpeg</a> project.</p>
<p>Assuming you already have Eclipse CDT, the first thing you need to do is create a new project.  After starting Eclipse, click on <strong>File-&gt;New-&gt;C Project</strong> and you&#8217;ll get a dialog box to choose the type of project (executable, static library, shared library, etc).  For this example, I&#8217;m choosing <strong>Executable </strong>and <strong>Hello World ANSI C Project</strong>.  Put in a name and click <strong>Finish</strong>.</p>
<p><a href="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/01-lec-new.png"><img class="size-medium wp-image-331 alignnone" title="01-lec-new" src="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/01-lec-new-300x264.png" alt="01-lec-new" width="300" height="264" /></a></p>
<p>Next you&#8217;ll see you have a new project in the left-side panel with a .c file containing a simple hello world program.</p>
<p><a href="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/02-lec-project.png"><img class="alignnone size-full wp-image-333" title="02-lec-project" src="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/02-lec-project.png" alt="02-lec-project" width="268" height="186" /></a></p>
<p>Now in my example I&#8217;ll add the line <strong>#include &lt;avcodec.h&gt;</strong> to set up my include.  If you need to add an include directory (where your header files are located) then in the Eclipse menu go to <strong>Project-&gt;Properties</strong> then open the <strong>C/C++ Build</strong> branch and click on <strong>Settings</strong>.  On the right side click on the <strong>Directories </strong>branch of <strong>GCC C Compiler</strong>.  You can then add directories to your include path.</p>
<p><a href="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/03-lec-include.png"><img class="alignnone size-medium wp-image-336" title="03-lec-include" src="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/03-lec-include-300x277.png" alt="03-lec-include" width="300" height="277" /></a></p>
<p>In this same dialog you can click on <strong>Libraries </strong>in the <strong>GCC C Linker</strong> branch to add any libraries to the project for linking.  The library I&#8217;m adding is the <strong>libavcodec.so</strong> shared library.  To add this (notice in the screenshot) I only need to add <strong>avcodec</strong>, without the prefix <strong>lib</strong> and <strong>.so</strong> extension.  This might be new to Windows programmers.  Since you&#8217;re adding a library it&#8217;s assumed to have the lib and .so in the name.</p>
<p><a href="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/04-lec-libs.png"><img class="alignnone size-medium wp-image-337" title="04-lec-libs" src="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/04-lec-libs-300x207.png" alt="04-lec-libs" width="300" height="207" /></a></p>
<p><iframe src="http://rcm.amazon.com/e/cm?t=homenick-20&#038;o=1&#038;p=13&#038;l=st1&#038;mode=books&#038;search=programming%20linux&#038;fc1=B85B5A&#038;lt1=_blank&#038;lc1=3366FF&#038;bg1=FAFAFA&#038;f=ifr" marginwidth="0" marginheight="0" width="468" height="60" border="0" frameborder="0" style="border:none;" scrolling="no"></iframe></p>
<p>Now let&#8217;s just add a couple of lines to the main() so we can test a compile with the libavcodec library.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;avcodec.h&gt;</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   avcodec_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   avcodec_register_all<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And then to run it, in the menu toolbar click on the run arrow and choose <strong>Run As-&gt;C/C++ Local Application</strong>.<br />
<a href="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/05-lec-run.png"><img class="alignnone size-medium wp-image-338" title="05-lec-run" src="http://whatwouldnickdo.com/wordpress/wp-content/uploads/2009/02/05-lec-run-300x108.png" alt="05-lec-run" width="300" height="108" /></a><br />
Getting no errors means success.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/328/eclipse-cdt-and-linux-libraries/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
