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:
//Invalid MEX-file
So I tried to comile with Matlab directly using MEX function. In "mex -setup" I chose
//Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2009a\sys\lcc
to compile with Matlab, but it only compile C and not C++ and my codes are in C++. Then I chose
//Microsoft Visual C++ 2008 SP1 in C:\Programme\Microsoft Visual Studio 9.0
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.
//Aria website where you can find header files: (http://robots.mobilerobots.com/wiki/ARIA)
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")
// Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
...
test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void _cdecl Aria::init(enum Aria::SigHandleMethod,bool,bool)" (_imp_?init@Aria@@SAXW4SigHandleMethod@1@_N1@Z) referenced in function _main test.mexw32 : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Link of 'test.mexw32' failed.
??? Error using ==> mex at 218 Unable to complete successfully. //
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.
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?