title: Octave sample code failing to compile in g++?
body: <p>I'm attempting to get the Octave C++ code <a href="http://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html" rel="nofollow">here</a> to compile in <code>g++ (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04) 4.6.4)</code>.</p>
  
  <p>This trimmed version of the above will compile in <code>g++</code>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;octave/oct.h&gt;
  using namespace std;
  
  int main() {
  //  Matrix L=Matrix(2,2);
  
    return 0;
  }
  </code></pre>
  
  <p>but if I unremark out the line <code>Matrix L=Matrix(2,2);</code> then compile with <code>g++ temp.cpp</code> it gives the error message:</p>
  
  <pre><code>/tmp/ccTa3Am5.o: In function `Array2&lt;double&gt;::~Array2()':
  temp.cpp:(.text._ZN6Array2IdED2Ev[_ZN6Array2IdED5Ev]+0x1f): undefined reference to `Array&lt;double&gt;::~Array()'
  /tmp/ccTa3Am5.o: In function `Array&lt;double&gt;::Array(dim_vector const&amp;)':
  temp.cpp:(.text._ZN5ArrayIdEC2ERK10dim_vector[_ZN5ArrayIdEC5ERK10dim_vector]+0x26): undefined reference to `Array&lt;double&gt;::get_size(dim_vector const&amp;)'
  /tmp/ccTa3Am5.o:(.rodata._ZTV5ArrayIdE[vtable for Array&lt;double&gt;]+0x10): undefined reference to `Array&lt;double&gt;::~Array()'
  /tmp/ccTa3Am5.o:(.rodata._ZTV5ArrayIdE[vtable for Array&lt;double&gt;]+0x18): undefined reference to `Array&lt;double&gt;::~Array()'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I'm unsure why.  Perhaps I'm missing an <code>#include</code>, perhaps I don't have an appropriate file installed, perhaps I'm not linking to the appropriate library, or perhaps I'm misusing Octave in some way.</p>
  
  <blockquote>
    <p><strong>Question</strong>:  Why is this failing to compile?  How can I fix it?</p>
  </blockquote>
  
  <p>It compiles fine if I use <code>mkoctfile --link-stand-alone temp.cpp</code> as indicated at the above site, however, I'd like to use <code>g++</code> if possible, since I eventually want to be able to call Octave functions from another program I've written in C++.</p>