Compiler properties for building MEX-files
이전 댓글 표시
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
답변 (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
Mohamed Abdalmoaty
2011년 7월 25일
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).
카테고리
도움말 센터 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!