title: Matlab / Microsoft Visual C++ 2010 Express: What is "error LNK2019: unresolved external symbol"?
body: <p>I am trying to create a simple C++ class and a Matlab mex file.  My code is as follows:</p>
  
  <p>Matlab: mexTest1.cpp</p>
  
  <pre><code>#include "mex.h"
  #include "K:\\My Documents\\Visual Studio 2010\\Projects\\HelloWorld\\HelloWorld\\Class1.h"
  
  /* Input Arguments */
  #define X   prhs[0]
  
  /* Output Arguments */
  #define RESULT  plhs[0]
  
  void mexFunction( int nlhs, mxArray *plhs[], 
            int nrhs, const mxArray *prhs[] ){ 
      /* Initialize input and output pointers
      // Inputs */
      double *x; 
      /* Outputs */
      double r;
      double *result; 
  
      mwSize m,n; 
  
      m = mxGetM(X); 
      n = mxGetN(X); 
  
      /* Create a matrix for the return argument */ 
      RESULT = mxCreateDoubleMatrix(1, 1, mxREAL);
      /* Assign pointers to the various parameters */ 
      result = mxGetPr(RESULT);
  
      x = mxGetPr(X);
  
      /* Do the actual computations in a subroutine */
      Class1 c1(2, 15.0);
      r = c1.product();
  
      result[0] = r;
      return;
  
  }
  </code></pre>
  
  <p>Class1.h:</p>
  
  <pre><code>#pragma once
  
  #include &lt;string&gt; // Standard string class in C++
  
  class Class1
  {
  public:
      int a;
      double b;
  public:
      Class1(const int&amp; a, const double&amp; b);
      //virtual ~Class1();
      void print() const;
      double product() const;
  };
  </code></pre>
  
  <p>Class1.cpp:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include "Class1.h"
  
  Class1::Class1(const int&amp; a, const double&amp; b){
      Class1::a = a;
      Class1::b = b;
  }
  
  void Class1::print() const{
      std::cout &lt;&lt; "a=" &lt;&lt; Class1::a &lt;&lt; " * b=" &lt;&lt; Class1::b &lt;&lt; " = " &lt;&lt; Class1::product() &lt;&lt; std::endl;
  }
  
  double Class1::product() const{
      return a*b;
  }
  </code></pre>
  
  <p>Running the Matlab command <code>mex mexTest1.cpp</code> gives the error messages:</p>
  
  <pre><code>Creating library C:\DOCUME~1\K\LOCALS~1\TEMP\MEX_RH~1\templib.x and object C:\DOCUME~1\K\LOCALS~1\TEMP\MEX_RH~1\templib.exp 
  mexTest1.obj : error LNK2019: unresolved external symbol "public: double __thiscall Class1::product(void)const " (?product@Class1@@QBENXZ) referenced in function _mexFunction 
  mexTest1.obj : error LNK2019: unresolved external symbol "public: __thiscall Class1::Class1(int const &amp;,double const &amp;)" (??0Class1@@QAE@ABHABN@Z) referenced in function _mexFunction 
  mexTest1.mexw32 : fatal error LNK1120: 2 unresolved externals 
  
    C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'mexTest1.mexw32' failed. 
  
  ??? Error using ==&gt; mex at 208
  Unable to complete successfully.
  </code></pre>
  
  <p>Can anyone help me fix this problem?</p>
  
  <p>Thanks.</p>