title: Compiling mex files with C++ through matlab: header files are not accessible
body: <p>I need to compile a mex file which is written in C++ (VS 2008) with Matlab 2009. If I compile with VS 2008 directly, it seems Matlab is not compatible and the error is:</p>
  
  <blockquote>
    <p>//Invalid MEX-file</p>
  </blockquote>
  
  <p>So I tried to comile with Matlab directly using MEX function. In "mex -setup" I chose </p>
  
  <blockquote>
    <p>//Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2009a\sys\lcc</p>
  </blockquote>
  
  <p>to compile with Matlab, but it only compile C and not C++ and my codes are in C++.
  Then I chose</p>
  
  <blockquote>
    <p>//Microsoft Visual C++ 2008 SP1 in C:\Programme\Microsoft Visual Studio 9.0</p>
  </blockquote>
  
  <p>to compile with VS 2008 from Matlab. For a simple test C++ file it worked. The mex file was perfect. Then I added some header files and a function to call a class in one of the header files. I added "Aria" header files to my project and the above error comes.</p>
  
  <blockquote>
    <p>//Aria website where you can find header files: (http://robots.mobilerobots.com/wiki/ARIA) </p>
  </blockquote>
  
  <p>Header files are in the same directory as main program, all the lib files are defined in VC++ project. In "Additional library directories" I added their path again. When I build my project through VC++, there is no error. But when I try to use MEX from Matlab, this error happens. (the name of C++ file is "test")</p>
  
  <blockquote>
    <p>//
    Microsoft (R) Incremental Linker Version 9.00.21022.08 </p>
    
    <p>Copyright (C) Microsoft Corporation.  All rights reserved. </p>
    
    <p>...</p>
    
    <p>test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void _<em>cdecl Aria::init(enum Aria::SigHandleMethod,bool,bool)" (</em>_imp_?init@Aria@@SAXW4SigHandleMethod@1@_N1@Z) referenced in function _main 
    test.mexw32 : fatal error LNK1120: 1 unresolved externals </p>
    
    <p>C:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Link of 'test.mexw32' failed. </p>
    
    <p>??? Error using ==> mex at 218
    Unable to complete successfully.
    //</p>
  </blockquote>
  
  <p>To test the project, I wrote a small class in one of that header files and used that class in C++ file, and it worked! I do not know why other classes do not work. They are linked to each other and they are about 140 .h files.</p>
  
  <p>Has anyone any idea why this happens?
  Why there is no error when I build, release and debug project in the VC++, but when I try to compile MEX file with Matlab, this error?</p>