Compiler properties for building MEX-files
5 次查看(过去 30 天)
显示 更早的评论
I'm working with MATLAB R2010b and need to compile a C++ source file to a .mex64 MEX-file.
I'm using the Microsoft VS2008 SP1 as a third party compiler.
mex.getCompilerConfigurations gives the following
mex.CompilerConfiguration
Package: mex
Properties:
Name: 'Microsoft Visual C++ 2008'
Manufacturer: 'Microsoft'
Language: 'C++'
Version: '9.0'
Location: 'C:\Program Files (x86)\Microsoft Visual Studio 9.0'
Details: [1x1 mex.CompilerConfigurationDetails]
So I think that the compiler is installed correctly. I tried to compile a simple hello.cpp file and it worked perfectly. However, my C++ source file requires the usage of MFC in a shared DLL. When I try to compile it in matlab using >>mex filenme.cpp I get the following error:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\INCLUDE\afx.h(24) : fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: Compile of 'filename.cpp' failed.
??? Error using ==> mex at 208
Unable to complete successfully.
How can I adjust the compiler used by MATLAB to use MFC in a Shared DLL? (as I guess that this is the problem, or?)
Thank you
0 个评论
回答(1 个)
Kaustubha Govind
2011-7-22
Perhaps you should build your code in the Visual Studio IDE directly. See Custom Building MEX-Files for some tips. I would recommend get a simple MEX example to compile on the IDE (without using the MATLAB mex command), before you try your code.
Once you can compile your MEX-function on the IDE, you might want to follow generic Visual Studio steps to use the MFC. For example, this page suggests setting:
Project + Properties, General. Ensure Use of MFC is set to "Use MFC in a Shared Library".
This will ensure that all Visual Studio settings are configured for use of the MFC.
2 个评论
Kaustubha Govind
2011-7-27
My best bet is that your Visual Studio project is not configured for an x64 target (by default, it is setup for a 32-bit target, and since libmat.lib, etc. are 64-bit libraries, they don't work with 32-bit projects).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Beamforming and Direction of Arrival Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!