<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>TomsBlog</title>
    <link>http://www.toms-blog.com/tags/curl/index.xml</link>
    <description>Recent content on TomsBlog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-uk</language>
    <atom:link href="http://www.toms-blog.com/tags/curl/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>C&#43;&#43; Eclipse and CURL libraries</title>
      <link>http://www.toms-blog.com/post/c&#43;&#43;-eclipse-and-curl-libraries/</link>
      <pubDate>Sat, 21 Sep 2013 15:09:16 +0000</pubDate>
      
      <guid>http://www.toms-blog.com/post/c&#43;&#43;-eclipse-and-curl-libraries/</guid>
      <description>&lt;p&gt;I’ve been working on a new C++ project with Eclipse and the CURL libraries and have been getting an undefined reference error.
I use Eclipse for all my IDE needs and combined with Eclipse CDT it is great for C++ projects.&lt;/p&gt;

&lt;p&gt;Whilst testing out the CURL libraries for my new project I encounter a problem with CURL and Eclipse and the g++ linker.
When building the project you may get the following errors complaining about an undefined reference:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;undefined reference to `curl_easy_init’&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So first things first is to check you have the ‘libcurl4-gnutls-dev’ libraries installed if you don’t then run:&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;apt-get install libcurl4-gnutls-dev
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now you need to work out where the libraries are installed, curl comes with a small package to determine this so run:&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;curl-config --libs
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This will then output commands you need to provide to the g++ linker in my case on Ubuntu 12.04 it was:&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;-L/usr/lib/x86_64-linux-gnu -lcurl -Wl,-Bsymbolic-functions -Wl,-z,relro
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So lets add the library path to Eclipse.&lt;/p&gt;

&lt;p&gt;Go to your project properties and then navigate to C/C++ Build -&amp;gt; Settings -&amp;gt; Cross G++ Linker -&amp;gt; Libraries&lt;/p&gt;

&lt;p&gt;Click Add and put the path found with the command curl-config –libs&lt;/p&gt;

&lt;p&gt;Now navigate to C/C++ Build -&amp;gt; Settings -&amp;gt; Cross G++ Linker -&amp;gt; Miscellaneous&lt;/p&gt;

&lt;p&gt;In the Linker flags field add everything else returned by the curl-config command:&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;-lcurl -Wl,-Bsymbolic-functions -Wl,-z,relro
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This should be it, but I encountered the same errors even after adding the libraries and flags. It turns out the command line pattern is wrong by default the flags are put straight after the g++ command. The flags in my case needed to be at the end of the g++ command.&lt;/p&gt;

&lt;p&gt;Whilst in the project Properties navigate to C/C++ Build -&amp;gt; Settings -&amp;gt; Cross G++ Linker. The default command line pattern is&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;COMMAND&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;FLAGS&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;OUTPUT_FLAG&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;OUTPUT_PREFIX&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;OUTPUT&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;INPUTS&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Change this so that ${FLAGS} appears at the end:&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;COMMAND&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;OUTPUT_FLAG&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;OUTPUT_PREFIX&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;OUTPUT&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;INPUTS&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color: #AA0000&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color: #003333&#34;&gt;FLAGS&lt;/span&gt;&lt;span style=&#34;color: #AA0000&#34;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now you should be able to build you C++ project with the CURL libraries from Eclipse.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>