VS2010与matlab R2011b混合编程遇到问题及解决

1.要生成C++动态链接库,在matlab命令窗口中输入:

>> mcc -W cpplib:ColorHarris -T link:lib ColorHarris -d F:\zhangying\xieyulin\cfile\

结果出现:Depfun error: 'Unable to locate ColorHarris as a function on the MATLAB path'

原因:当前编译路径没有修改,错误已经提示了,将当前matlab路径改到你这个m文件所在的路径下,(点击运行按钮会出现 change directory,选择即可)再进行编译!

2.在VS2010中执行到:

if( !ColorHarrisInitialize())
    {
         std::cout << "Could not initialize ColorHarris!" << std::endl;
    }

时出现:cannot open CTF archive file

'c:\document~1\jiao\local~1\Temp\mathworks_tem_2696_2808'

or

'c:\document~1\jiao\local~1\Temp\mathworks_tem_2696_2808.zip'

这个问题查了很长时间也没查出来解决方法,后来新建了工程,重新添加文件,结果突然没这个问题了。。就这么不了了之。。。

参考博客: http://blog.sina.com.cn/s/blog_4fc6546101011cu5.html

3.将matlab的m文件用mcc生成.h .lib .dll 文件后拷贝到VS2010项目根目录中,结果运行时提示编译的应用程序或DLL为无效的windows映像。

分析:查了很长时间,觉得应该是拷贝的过程中损坏了dll文件

解决:在编译时就将生成文件的所在目录指定为VS2010项目根目录,保留.h .lib .dll 文件,再将其他文件项删除即可。为了保险,用mcc -c 生成ctf文件也放在根目录下,运行通过。

4.在VS2010调用matlab文件时,提示 Undefinedfunction “myfun1”  for input arguments of type 'double'.

分析:myfun1与调用的matlab主函数不在同一个文件夹里,在matlab中运行时不会出现找不到函数的问题(还是觉得matlab很智能啊)。但VS2010找不到放在另一个文件夹里的函数,是路径的问题。

解决:将myfun1.m拷贝到调用的matlab主函数同一个路径下(放在同一个文件夹里),运行通过。

posted @ 2012-11-11 11:10  微雪  阅读(5417)  评论(1编辑  收藏  举报