title: Compile and run libconfig++
body: <p>I installed:</p>
  
  <pre><code>sudo apt-get install libconfig++-dev
  </code></pre>
  
  <p>After that I want compile and run the example program libconfig++.</p>
  
  <p>Program:</p>
  
  <pre><code>/* ----------------------------------------------------------------------------
     libconfig - A library for processing structured configuration files
     Copyright (C) 2005-2010  Mark A Lindner
  
     This file is part of libconfig.
  
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     as published by the Free Software Foundation; either version 2.1 of
     the License, or (at your option) any later version.
  
     This library is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Lesser General Public License for more details.
  
     You should have received a copy of the GNU Library General Public
     License along with this library; if not, see
     &lt;http://www.gnu.org/licenses/&gt;.
     ----------------------------------------------------------------------------
  */
  
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cstdlib&gt;
  #include &lt;libconfig.h++&gt;
  
  using namespace std;
  using namespace libconfig;
  
  // This example reads the configuration file 'example.cfg' and displays
  // some of its contents.
  
  int main(int argc, char **argv)
  {
    Config cfg;
  
    // Read the file. If there is an error, report it and exit.
    try
    {
      cfg.readFile("example.cfg");
    }
    catch(const FileIOException &amp;fioex)
    {
      std::cerr &lt;&lt; "I/O error while reading file." &lt;&lt; std::endl;
      return(EXIT_FAILURE);
    }
    catch(const ParseException &amp;pex)
    {
      std::cerr &lt;&lt; "Parse error at " &lt;&lt; pex.getFile() &lt;&lt; ":" &lt;&lt; pex.getLine()
                &lt;&lt; " - " &lt;&lt; pex.getError() &lt;&lt; std::endl;
      return(EXIT_FAILURE);
    }
  
    // Get the store name.
    try
    {
      string name = cfg.lookup("name");
      cout &lt;&lt; "Store name: " &lt;&lt; name &lt;&lt; endl &lt;&lt; endl;
    }
    catch(const SettingNotFoundException &amp;nfex)
    {
      cerr &lt;&lt; "No 'name' setting in configuration file." &lt;&lt; endl;
    }
  
    const Setting&amp; root = cfg.getRoot();
  
    // Output a list of all books in the inventory.
    try
    {
      const Setting &amp;books = root["inventory"]["books"];
      int count = books.getLength();
  
      cout &lt;&lt; setw(30) &lt;&lt; left &lt;&lt; "TITLE" &lt;&lt; "  "
           &lt;&lt; setw(30) &lt;&lt; left &lt;&lt; "AUTHOR" &lt;&lt; "   "
           &lt;&lt; setw(6) &lt;&lt; left &lt;&lt; "PRICE" &lt;&lt; "  "
           &lt;&lt; "QTY"
           &lt;&lt; endl;
  
      for(int i = 0; i &lt; count; ++i)
      {
        const Setting &amp;book = books[i];
  
        // Only output the record if all of the expected fields are present.
        string title, author;
        double price;
        int qty;
  
        if(!(book.lookupValue("title", title)
             &amp;&amp; book.lookupValue("author", author)
             &amp;&amp; book.lookupValue("price", price)
             &amp;&amp; book.lookupValue("qty", qty)))
          continue;
  
        cout &lt;&lt; setw(30) &lt;&lt; left &lt;&lt; title &lt;&lt; "  "
             &lt;&lt; setw(30) &lt;&lt; left &lt;&lt; author &lt;&lt; "  "
             &lt;&lt; '$' &lt;&lt; setw(6) &lt;&lt; right &lt;&lt; price &lt;&lt; "  "
             &lt;&lt; qty
             &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
    }
    catch(const SettingNotFoundException &amp;nfex)
    {
      // Ignore.
    }
  
    // Output a list of all books in the inventory.
    try
    {
      const Setting &amp;movies = root["inventory"]["movies"];
      int count = movies.getLength();
  
      cout &lt;&lt; setw(30) &lt;&lt; left &lt;&lt; "TITLE" &lt;&lt; "  "
           &lt;&lt; setw(10) &lt;&lt; left &lt;&lt; "MEDIA" &lt;&lt; "   "
           &lt;&lt; setw(6) &lt;&lt; left &lt;&lt; "PRICE" &lt;&lt; "  "
           &lt;&lt; "QTY"
           &lt;&lt; endl;
  
      for(int i = 0; i &lt; count; ++i)
      {
        const Setting &amp;movie = movies[i];
  
        // Only output the record if all of the expected fields are present.
        string title, media;
        double price;
        int qty;
  
        if(!(movie.lookupValue("title", title)
             &amp;&amp; movie.lookupValue("media", media)
             &amp;&amp; movie.lookupValue("price", price)
             &amp;&amp; movie.lookupValue("qty", qty)))
          continue;
  
        cout &lt;&lt; setw(30) &lt;&lt; left &lt;&lt; title &lt;&lt; "  "
             &lt;&lt; setw(10) &lt;&lt; left &lt;&lt; media &lt;&lt; "  "
             &lt;&lt; '$' &lt;&lt; setw(6) &lt;&lt; right &lt;&lt; price &lt;&lt; "  "
             &lt;&lt; qty
             &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
    }
    catch(const SettingNotFoundException &amp;nfex)
    {
      // Ignore.
    }
  
    return(EXIT_SUCCESS);
  }
  
  // eof
  </code></pre>
  
  <p>Example config file:</p>
  
  <pre><code>// An example configuration file that stores information about a store.
  
  // Basic store information:
  name = "Books, Movies &amp; More";
  
  // Store inventory:
  inventory =
  {
    books = ( { title  = "Treasure Island";
                author = "Robert Louis Stevenson";
                price  = 29.99;
                qty    = 5; },
              { title  = "Snow Crash";
                author = "Neal Stephenson";
                price  = 9.99;
                qty    = 8; }
            );
  
    movies = ( { title = "Brazil";
                 media = "DVD";
                 price = 19.99;
                 qty = 11; },
               { title = "The City of Lost Children";
                 media = "DVD";
                 price = 18.99;
                 qty = 5; },
               { title = "Memento";
                 media = "Blu-Ray";
                 price = 24.99;
                 qty = 20;
               },
               { title = "Howard the Duck"; }
             );
  };
  
  // Store hours:
  hours =
  {
    mon = { open =  9; close = 18; };
    tue = { open =  9; close = 18; };
    wed = { open =  9; close = 18; };
    thu = { open =  9; close = 18; };
    fri = { open =  9; close = 20; };
    sat = { open =  9; close = 20; };
    sun = { open = 11; close = 16; };
  };
  </code></pre>
  
  <p>I`m trying e.g.:</p>
  
  <pre><code>g++ -lconfig++ example1.cpp -o example1
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>/tmp/ccOI0efx.o: In function `main':
  example1.cpp:(.text+0x21): undefined reference to `libconfig::Config::Config()' (..)
  </code></pre>
  
  <p>How to compile this program? What is necessary command?</p>
  
  <p>Another way:
  I also downloaded package:
  libconfig-1.4.9.tar.gz
  extract and done "Install" file, I mean:</p>
  
  <p>The simplest way to compile this package is:</p>
  
  <ol>
  <li><p><code>cd' to the directory containing the package's source code and type
  </code>./configure'...</p></li>
  <li><p>Type `make' to compile the package.</p></li>
  <li><p>Optionally, type `make check'...</p></li>
  <li><p>Type `make install' to install the programs and any data files and
   documentation.</p></li>
  <li><p>You can remove the program binaries and object files from the
   source code directory by typing `make clean'...
  After that try to run c++ example
  (cd examples/c++ and make) nothing to do?</p></li>
  </ol>
  
  <p>Output:</p>
  
  <pre><code>make: *** No rule to make target `../../lib/libconfig++.la', required by `example1'. Stop.
  </code></pre>