MATLAB R2010b, Visual Studio 2008 Pro, 64-bit Windows 7
What are the necessary settings in VS to call Matlab from a C program?
Compiling from the command-line or within Matlab are not options,
since I need to debug the C program within VS.
Cannot find info in the documentation. Did I miss something?
Best
|
|
0
|
|
|
|
Reply
|
sk366
|
11/17/2010 4:25:21 PM |
|
sk366 <skalra.366@gmail.com> wrote in message <810f102b-f2f2-42f8-b28a-a894c8e617ad@26g2000yqv.googlegroups.com>...
> MATLAB R2010b, Visual Studio 2008 Pro, 64-bit Windows 7
>
> What are the necessary settings in VS to call Matlab from a C program?
>
> Compiling from the command-line or within Matlab are not options,
> since I need to debug the C program within VS.
>
> Cannot find info in the documentation. Did I miss something?
>
> Best
Build the C code using the mex command line with the "-g" option. Open the project in Visual Studio, and go to "Tools->Attach to Process", select Matlab, and attach. Put a breakpoint on the first statement within the mex function, which will allow you to debug your mex file.
|
|
0
|
|
|
|
Reply
|
Jeff
|
11/17/2010 4:57:05 PM
|
|
On Nov 17, 9:57=A0pm, "Jeff Gullett" <Jeffrey.Gull...@ngc.com> wrote:
> Build the C code using the mex command line with the "-g" option. =A0Open=
the project in Visual Studio, and go to "Tools->Attach to Process", select=
Matlab, and attach. =A0Put a breakpoint on the first statement within the =
mex function, which will allow you to debug your mex file.
Thanks Jeff. Is it possible to do the build, debug cycle within Visual
Studio?
If not possible, then what are the settings for the project?
|
|
0
|
|
|
|
Reply
|
sk366
|
11/17/2010 6:07:19 PM
|
|
sk366 <skalra.366@gmail.com> wrote in message <238ca000-a9d9-4504-87a4-94a201ec2d08@l32g2000yqc.googlegroups.com>...
> On Nov 17, 9:57 pm, "Jeff Gullett" <Jeffrey.Gull...@ngc.com> wrote:
> > Build the C code using the mex command line with the "-g" option. Open the project in Visual Studio, and go to "Tools->Attach to Process", select Matlab, and attach. Put a breakpoint on the first statement within the mex function, which will allow you to debug your mex file.
>
> Thanks Jeff. Is it possible to do the build, debug cycle within Visual
> Studio?
>
> If not possible, then what are the settings for the project?
I haven't yet discovered a way to do the build from within VS, but I'm almost certain it would be possible given you have enough time to figure it out. I think you would probably have to do the compilation using VS (so you need to know which matlab libraries to include in the compilation stage), then change the linker command line to be a call to the mex funtion, passing in the resulting *.obj files.
This approach is just a guess given I have never tried to do this. Instead, I find it easier to write a batch file that mex's the code for me.
Typically, I build by specifying the code files, which completely ignores all project settings. If you do this, your project settings are irrelevant. My mex debug build command typically looks something like the following:
mex -g -I".." "Mex Function.cpp" "..\Some Other Include.cpp"
Just be sure to "-I" all of the directories that contain your header files and explicitly include all *.cpp/*.c files on the command line.
|
|
0
|
|
|
|
Reply
|
Jeff
|
11/17/2010 6:38:04 PM
|
|
Jeff, appreciate the effort, but I do not know enough to figure it out
myself.
The question is still open---I am looking for a method that is tested
and shown to work.
|
|
0
|
|
|
|
Reply
|
sk366
|
11/17/2010 6:52:00 PM
|
|
sk366 <skalra.366@gmail.com> wrote in message <4d603070-5b21-4645-a7f4-1378652a5662@j2g2000yqf.googlegroups.com>...
> Jeff, appreciate the effort, but I do not know enough to figure it out
> myself.
>
> The question is still open---I am looking for a method that is tested
> and shown to work.
Sorry I'm unable to help further. I do know you could set it up to build from within Visual Studio, but I don't think it is possible to debug in VS without using Matlab because you can't pass Matlab objects into/out of your mex file without using the Matlab interface. I guess you could get around this by calling matlab as a post-build event with commands to exercise your mex file, or perhaps by writing a "main" function that creates Matlab objects in C++ then calls your mex function, but I really don't see how either of these options is any better than debugging by attaching to the Matlab process. Even with a "method that is tested and shown to work", you will still most certainly have to put in ~80 man-hours to do something that takes ~2 minutes using the "attach to process" method.
If I am misunderstanding your request, please let me know.
|
|
0
|
|
|
|
Reply
|
Jeff
|
11/17/2010 8:15:07 PM
|
|
sk366 wrote:
> Jeff, appreciate the effort, but I do not know enough to figure it out
> myself.
>
> The question is still open---I am looking for a method that is tested
> and shown to work.
What's wrong w/ the "attach process" option Jeff outlined?
It's in essence as if you were doing any other mixed-language
programming with the main program something other than your DLL language.
You can certainly build the DLL in VS; to set up VS to do so, look at
the mex batch file and see the options used and libraries and set them
manually in the IDE as well as the INCLUDE paths, etc.
Still, to invoke the DLL you'll have to execute ML or build a test
harness app that simulates the call...
What problem are you trying to solve?
--
|
|
0
|
|
|
|
Reply
|
dpb
|
11/17/2010 8:39:48 PM
|
|
Based on the original question and replies, it's not clear whether you are calling C code from MATLAB (a MEX file) or executing MATLAB commands from within a C program (using the MATLAB Engine interface). If you are trying to do the former, then you might as well use mex to build the DLL from within MATLAB and then follow the debugging guidelines described previously.
If you are trying to build an Engine application, then you can look in <matlabroot>\bin\win64\mexopts and look for the appropriate batch file <your_compiler>engmatopts.bat. It will contain the compiling and linking flags it would use when calling VS from the command line (and also the additional libraries to link against). You can then set these options in your project. It may take a little digging to locate them all, but it isn't too difficult.
Hope this helps,
-Andy
dpb <none@non.net> wrote in message <ic1era$vcp$1@news.eternal-september.org>...
> sk366 wrote:
> > Jeff, appreciate the effort, but I do not know enough to figure it out
> > myself.
> >
> > The question is still open---I am looking for a method that is tested
> > and shown to work.
>
> What's wrong w/ the "attach process" option Jeff outlined?
>
> It's in essence as if you were doing any other mixed-language
> programming with the main program something other than your DLL language.
>
> You can certainly build the DLL in VS; to set up VS to do so, look at
> the mex batch file and see the options used and libraries and set them
> manually in the IDE as well as the INCLUDE paths, etc.
>
> Still, to invoke the DLL you'll have to execute ML or build a test
> harness app that simulates the call...
>
> What problem are you trying to solve?
>
> --
|
|
0
|
|
|
|
Reply
|
Andrew
|
11/17/2010 9:49:27 PM
|
|
Some clarifications.
1. Need to call Matlab from C not the other way around. Executing
MATLAB commands from within a C program. Not building a DLL.
2. Do not need to debug within the call to Matlab; the Matlab call is
like a black-box.
3. For reasons not directly relevant here, building within Matlab or
using the command-line is not an option.
4. I do not have the experience or the time to figure out all the
details--so no guesses please.
Given the above constraints, is it possible to build and debug within
VS?
If so, are there a set of instructions available in the Matlab
documentation or elsewhere?
If this has not been done or details are not available, then I have no
choice but to leave it for another day.
|
|
0
|
|
|
|
Reply
|
sk366
|
11/18/2010 3:29:53 AM
|
|
Will someone from Mathworks provide the answer?
|
|
0
|
|
|
|
Reply
|
sk366
|
11/19/2010 5:03:43 PM
|
|
On 19/11/10 11:03 AM, sk366 wrote:
> Will someone from Mathworks provide the answer?
If you are asking that, you should probably be putting the matter to
Mathwork's Technical Support. The Mathworks people who happen to post
here do so as volunteers. Each of them has their areas of specialty; I
am not _aware_ of any current Mathworks volunteer who happens to work in
the area you are hoping for assistance on. And you did say that you
don't want guesses.
|
|
0
|
|
|
|
Reply
|
Walter
|
11/19/2010 5:44:21 PM
|
|
Thanks Walter. I am surprised at the lack of response--was expecting a
concrete answer. Assumed I missed it in the documentation.
VS is one of the two compilers supported by Matlab; calling Matlab
from VS while building and debugging should be standard operations.
That doesn't seem to be the case.
A suggestion/guess helps when one knows enough or has time.
Unfortunately I am constrained in both.
|
|
0
|
|
|
|
Reply
|
sk366
|
11/19/2010 6:49:56 PM
|
|
I'm not sure if this is exactly what you're after, but we build and debug mex files in Visual Studio all the time. We call mex dll's from MATLAB, not MATLAB from C/C++, but I think this setup will work.
In your project properties, under Configuration Properties -> C/C++ -> General, add the <MATLAB>\<arch>\extern\include directory to the "Additional Include Directories" line.
Under Linker -> General, add <MATLAB>\<arch>\extern\lib\<arch>\microsoft to the "Additional Library Directories" line.
Under Linker -> Input, add the necessary Matlab libs to "Additional Dependencies" (libmx.lib libmex.lib).
Now, when you are calling your dll from MATLAB, you need to add a .def file that exports your mexFunction. This doesn't look to apply in your case.
Build your solution.
Finally, start MATLAB and select it under Debug -> "Attach to Process". Debug away!
|
|
0
|
|
|
|
Reply
|
Jeremy
|
12/6/2010 2:46:05 PM
|
|
|
12 Replies
898 Views
(page loaded in 0.126 seconds)
Similiar Articles: Calling MATLAB from Visual Studio in a C program - comp.soft-sys ...MATLAB R2010b, Visual Studio 2008 Pro, 64-bit Windows 7 What are the necessary settings in VS to call Matlab from a C program? Compiling from th... Calling Matlab engine from C++ - comp.soft-sys.matlabCalling MATLAB from Visual Studio in a C program - comp.soft-sys ... Calling Matlab engine from C++ - comp.soft-sys.matlab Calling MATLAB from Visual Studio in a C program ... BUG: simulink 7.6 (r2010b) and visual c++ 2010 compiler - comp ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... BUG: simulink 7.6 (r2010b) and visual c++ 2010 compiler - comp ... Calling MATLAB from Visual Studio ... Compiling MCR C++ dll with VS2010 - comp.soft-sys.matlab ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... Calling MATLAB from Visual Studio ... How to make Matlab R2009b recognize Visual Studio 2010 - comp.soft ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... MATLAB R2010b, Visual Studio 2008 Pro, 64-bit Windows 7 What are the ... It should call the Visual C++ ... call matlab from python (WinXP) - comp.soft-sys.matlabCalling MATLAB from Visual Studio in a C program - comp.soft-sys ... Calling .dll library: Method was not found - comp.soft-sys.matlab ... call matlab from python (WinXP ... mbuild not recognizing Visual C++ 2010 - comp.soft-sys.matlab ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... mbuild not recognizing Visual C++ 2010 - comp.soft-sys.matlab ... Calling MATLAB from Visual Studio in ... Executing Matlab code using Visual basic - comp.soft-sys.matlab ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... Executing Matlab code using Visual basic - comp.soft-sys.matlab ... Calling MATLAB from Visual Studio ... Debugging C MEX S-functions with Visual Studio .NET - comp.soft ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... COMPGROUPS.NET ... the = mex function, which will allow you to debug your mex file. calling a VB6 .DLL from java - comp.lang.java.helpCalling MATLAB from Visual Studio in a C program - comp.soft-sys ... calling a VB6 .DLL from java - comp.lang.java.help Calling MATLAB from Visual Studio in a C program ... Implement MATLAB code in Visual Studio .NET - comp.soft-sys.matlab ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... Hope this helps, -Andy dpb <none@non.net> wrote in message ... Implement MATLAB code in Visual Studio ... How to use MATLAB R2007b with Microsoft Visual Studio 2008? - comp ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... How to use MATLAB R2007b with Microsoft Visual Studio 2008? - comp ... Calling MATLAB from Visual ... Compilation error with C++ mex file - comp.soft-sys.matlab ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... I think you would probably have to do the compilation using VS (so you need ... question and replies ... From NASM to Visusal Studio source debugging - comp.lang.asm.x86 ...Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... From NASM to Visusal Studio source debugging - comp.lang.asm.x86 ... debugging c program - comp ... converting C/Visual BASIC code to MATLAB - comp.soft-sys.matlab ...Executing Matlab code using Visual basic - comp.soft-sys.matlab ... Calling MATLAB from Visual Studio in a C program - comp.soft-sys ... Executing Matlab code using Visual ... Calling MATLAB from Visual Studio in a C program - comp.soft-sys ...MATLAB R2010b, Visual Studio 2008 Pro, 64-bit Windows 7 What are the necessary settings in VS to call Matlab from a C program? Compiling from th... Calling MATLAB from Visual Studio in a C program - Newsreader ...MATLAB R2010b, Visual Studio 2008 Pro, 64-bit Windows 7 What are the necessary settings in VS to call Matlab from a C program? Compiling from the command-line or ... 7/20/2012 9:56:25 AM
|