C#调用matlab生成的dll文件问题
2014-09-26 20:33
489 查看
我使用的是:VS 2008, matlab R2009a;
1. 首先遇到的第一个问题是:**** 类型初始值设定项引发异常.
在网上搜到一篇文章,摘录如下:http://blog.sina.com.cn/s/blog_6622f5c30100hhja.html
安装MCRInstall.exe,我安装完Matlab之后在这里找得的:D:"Program Files\MATLAB\R2009b\toolbox\compiler\deploy\win32
点击:我的电脑-属性-高级-环境变量-系统变量-PATH-编辑,在变量值输入框中,不要删除以前的字符串,在最前面加入MCR的安装路径,如:D:"Program Files\MATLAB\MATLAB Compiler Runtime\v80\bin\win32; 然后确定、保存、重启电脑。(我就是不知道需要这两步,老是在C#创建Matlab的访问对象时,出现:“xxx的类型初始值设定项引发异常。”,完全不理解是什么原因,被耽搁了大量时间,直到安装了Matlab 2008b,仔细阅读它生成的readme.txt才知道)
第二步: 在matlab的Command window中输入mbuild -setup显示如下
>> mbuild -setup
Please choose your compiler for building standalone MATLAB applications: Would you like mbuild to locate installed compilers [y]/n? n %选择n
Select a compiler:
[1] Lcc-win32 C 2.4.1
[2] Microsoft Visual C++ 6.0
[3] Microsoft Visual C++ .NET 2003
[4] Microsoft Visual C++ 2005
[5] Microsoft Visual C++ 2005 Express Edition
[6] Microsoft Visual C++ 2008
[0] None Compiler: 4 %选择4,其他编译器可以选相应的选项,我没有验证过
The default location for Microsoft Visual C++ 2008 compilers is C:\Program Files\Microsoft Visual Studio 8, but that directory does not exist on this machine.
Use C:\Program Files\Microsoft Visual Studio 8.0 anyway [y]/n? n%选择n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio 9] D:\Program Files\Microsoft Visual Studio 8.0 %选择您自己的当前安装路径
Please verify your choices: Compiler: Microsoft Visual C++ 2005 Location: D:\Program Files\Microsoft Visual Studio 8.0 Are these correct [y]/n? y %看上述信息,如果正确选择y
Warning: MBUILD requires that the Microsoft Visual C++ 8.0 directories "VC" and "Common7" be located within the same parent directory. MBUILD setup expected to find directories named "Common7" and "VC" in the directory: "C:\Program Files\Microsoft Visual Studio
8". Trying to update options file: C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2009a\compopts.bat From template: D:\PROGRA~1\MATLAB\R2009a\bin\win32\mbuildopts\msvc80compp.bat Done . . . 到此matlab编译器设置成功。
第三步: 编写m文件:
function y=mymagic(x)
y=magic(x);
第四步:建立项目:
在matlab中点击“File- new -Development Project” 自己选择项目保存目录和项目名,如E:"和magicpro.prj 类 型选择.NET Component,如果你要生成更通用的COM组件,选择Generic COM Component。添加刚才的m文件到这个新建的项目中去。点击Build the project按钮(这个按钮的图标和微软开发工具的Build图标一样)或者右击选择“build”,等待3,4分钟。建立成功。
2. 以上问题解决之后,第二个问题,出现R6034错误。解决方法摘录如下:
http://topic.csdn.net/u/20090818/13/0ef04814-4ced-4e53-8d04-53cc5ee88800.html
http://blog.sina.com.cn/s/blog_6622f5c30100n39e.html
1、在MCR安装目录下D:\Program Files\MATLAB\MATLAB Compiler Runtime\v710\bin\win32下有一个tbbmalloc.dll ,将这个dll文件复制一份;
2、将tbbmalloc.dll 重命名为tbbmalloc.dll.bak;
3、在Visual Studio 命令提示符下:输入以下的命令:cd D:\Program Files\MATLAB\MATLAB Compiler Runtime\v710\bin\win32
再输入命令mt.exe -inputresource:libut.dll;#2 -outputresource:tbbmalloc.dll;#2
执行命令后会在tbbmalloc.dll 中包含一些清单(manifests)。这样就不会出现r6034错误了。
4、将所有出现r6034错误的机子上,用新的tbbmalloc.dll 替换原来的tbbmalloc.dll 文件
加:matlab文件目录中不能含义空格或者中文字符。
------------------------------------------
最后,还出现了其他的问题,现在还没解决,只是,忽略问题的话,程序可以继续往下跑。
1. 首先遇到的第一个问题是:**** 类型初始值设定项引发异常.
在网上搜到一篇文章,摘录如下:http://blog.sina.com.cn/s/blog_6622f5c30100hhja.html
安装MCRInstall.exe,我安装完Matlab之后在这里找得的:D:"Program Files\MATLAB\R2009b\toolbox\compiler\deploy\win32
点击:我的电脑-属性-高级-环境变量-系统变量-PATH-编辑,在变量值输入框中,不要删除以前的字符串,在最前面加入MCR的安装路径,如:D:"Program Files\MATLAB\MATLAB Compiler Runtime\v80\bin\win32; 然后确定、保存、重启电脑。(我就是不知道需要这两步,老是在C#创建Matlab的访问对象时,出现:“xxx的类型初始值设定项引发异常。”,完全不理解是什么原因,被耽搁了大量时间,直到安装了Matlab 2008b,仔细阅读它生成的readme.txt才知道)
第二步: 在matlab的Command window中输入mbuild -setup显示如下
>> mbuild -setup
Please choose your compiler for building standalone MATLAB applications: Would you like mbuild to locate installed compilers [y]/n? n %选择n
Select a compiler:
[1] Lcc-win32 C 2.4.1
[2] Microsoft Visual C++ 6.0
[3] Microsoft Visual C++ .NET 2003
[4] Microsoft Visual C++ 2005
[5] Microsoft Visual C++ 2005 Express Edition
[6] Microsoft Visual C++ 2008
[0] None Compiler: 4 %选择4,其他编译器可以选相应的选项,我没有验证过
The default location for Microsoft Visual C++ 2008 compilers is C:\Program Files\Microsoft Visual Studio 8, but that directory does not exist on this machine.
Use C:\Program Files\Microsoft Visual Studio 8.0 anyway [y]/n? n%选择n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio 9] D:\Program Files\Microsoft Visual Studio 8.0 %选择您自己的当前安装路径
Please verify your choices: Compiler: Microsoft Visual C++ 2005 Location: D:\Program Files\Microsoft Visual Studio 8.0 Are these correct [y]/n? y %看上述信息,如果正确选择y
Warning: MBUILD requires that the Microsoft Visual C++ 8.0 directories "VC" and "Common7" be located within the same parent directory. MBUILD setup expected to find directories named "Common7" and "VC" in the directory: "C:\Program Files\Microsoft Visual Studio
8". Trying to update options file: C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2009a\compopts.bat From template: D:\PROGRA~1\MATLAB\R2009a\bin\win32\mbuildopts\msvc80compp.bat Done . . . 到此matlab编译器设置成功。
第三步: 编写m文件:
function y=mymagic(x)
y=magic(x);
第四步:建立项目:
在matlab中点击“File- new -Development Project” 自己选择项目保存目录和项目名,如E:"和magicpro.prj 类 型选择.NET Component,如果你要生成更通用的COM组件,选择Generic COM Component。添加刚才的m文件到这个新建的项目中去。点击Build the project按钮(这个按钮的图标和微软开发工具的Build图标一样)或者右击选择“build”,等待3,4分钟。建立成功。
2. 以上问题解决之后,第二个问题,出现R6034错误。解决方法摘录如下:
http://topic.csdn.net/u/20090818/13/0ef04814-4ced-4e53-8d04-53cc5ee88800.html
http://blog.sina.com.cn/s/blog_6622f5c30100n39e.html
1、在MCR安装目录下D:\Program Files\MATLAB\MATLAB Compiler Runtime\v710\bin\win32下有一个tbbmalloc.dll ,将这个dll文件复制一份;
2、将tbbmalloc.dll 重命名为tbbmalloc.dll.bak;
3、在Visual Studio 命令提示符下:输入以下的命令:cd D:\Program Files\MATLAB\MATLAB Compiler Runtime\v710\bin\win32
再输入命令mt.exe -inputresource:libut.dll;#2 -outputresource:tbbmalloc.dll;#2
执行命令后会在tbbmalloc.dll 中包含一些清单(manifests)。这样就不会出现r6034错误了。
4、将所有出现r6034错误的机子上,用新的tbbmalloc.dll 替换原来的tbbmalloc.dll 文件
加:matlab文件目录中不能含义空格或者中文字符。
------------------------------------------
最后,还出现了其他的问题,现在还没解决,只是,忽略问题的话,程序可以继续往下跑。
相关文章推荐
- VS2010 C#中调用matlab2014a生成的dll的几个问题
- C#调用MFC程序DLL库——MFC项目DLL生成问题、DLL引用链问题、DLL读取配置文件路径问题
- 用C#调用matlab中生成的dll文件
- matlab生成VS可调用的dll文件
- 关于使用vc++调用matlab生成的dll传递数组的问题
- C# 调用WebService的3种方式 :直接调用、根据wsdl生成webservice的.cs文件及生成dll调用、动态调用
- C#调用matlab dll出现的怪问题-----折腾matlab dll好久了
- C#调用C++写的dll文件出错问题msvcr100.dll
- VC与Matlab混合编程(在VC中调用.m文件编译生成的DLL)
- C#调用Matlab生成的dll方法的详细说明_C#教程
- 在VS2010上使用C#调用非托管C++生成的DLL文件
- Labwindows/CVI程序调用C#生成的Dll文件
- 【转】C#生成dll文件:如何用C#编译生成dll文件即动态链接库文件供其它程序调用
- 在VS2010上使用C#调用非托管C++生成opencv代码的DLL文件
- C#调用Matlab生成的dll方法的详细说明
- C#调用Matlab生成的dll方法的详细说明
- 64位win7下vc2010如何调用matlab2012a中生成的dll文件
- C#调用C++生成的Dll调试异常的问题
- MATLAB.NET混合编程之二~~由C#调用MATLAB编译生成的dll
- 将C语言编译成DLL并用C#进行调用以及关于从C#传输中文路径到C的DLL中打开文件的问题