title: Undefined symbols when using curl in C++
body: <p>I want to get a file via http using curl. My environment is GCC (Mac OS X). I've created a simple class Shared to use it smth like this:</p>
  
  <pre><code>#include "Shared.h"
  ...
  std::string str = Shared::getHTTPFile( "http://google.com" );
  </code></pre>
  
  <p>When I try to compile it with the following command:</p>
  
  <pre><code>g++ -o test -l curl test.cpp
  </code></pre>
  
  <p>I get an error message:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
  "Shared::curlBuffer", referenced from:
   Shared::getHTTPFile(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in test-a10048.o
   Shared::writer(char*, unsigned long, unsigned long, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;*) in test-a10048.o
  "Shared::errorBuffer", referenced from:
   Shared::getHTTPFile(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in test-a10048.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>My code of Shared class is just simple:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;stdio.h&gt;
  #include &lt;curl/curl.h&gt;
  
  class Shared {
  
  public:
      static char errorBuffer[ CURL_ERROR_SIZE ];
      static std::string curlBuffer;
      static int writer( char *data, size_t size, size_t nmemb, std::string *buffer ) {
          curlBuffer.append( data, size * nmemb );
          int result = size * nmemb;
          return result;
      }
  
      static std::string getHTTPFile( std::string url ) {
          CURL *curl = curl_easy_init();
          CURLcode result;
          if (curl) {
              curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
              curl_easy_setopt(curl, CURLOPT_URL, "http://google.com" );
              curl_easy_setopt(curl, CURLOPT_HEADER, 1);
              curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer );
              curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;curlBuffer );
              result = curl_easy_perform( curl );
          }
          curl_easy_cleanup(curl);
          return 0;
      }
  };
  </code></pre>
  
  <p>What do I do wrong here?</p>