帮助:VS2005编译*.m文件
我有 test.m(matlab 源代码)文件
,它实现了 A() 函数;和 main.cpp 文件(将调用 A() )。
如您所知,我们可能会按照以下步骤进行:
使用matlab编译test.m(mcc -),将生成:test.dll,test.ctf,test.h。
将test.dll和test.ctf、test.h文件复制到VS2005项目中。在main.cpp中,调用test.dll中的A()。
但是,当我发布程序时,我也会将test.dll打包在一起。
另一种方式,我可以使用VS2005编译test.m和main.cpp,这只会生成main.dll,main.ctf,main.h ..(我只会释放main.dll,main.ctf,main .h,)。
这意味着,我将 test.m 编译到 main.cpp 中。
我已经尝试过这种方式,在VS2005 --->构建事件-->预构建事件-->命令行: mcc C -w lib:test test.m
它将生成中间文件 test.ctf(仅 test.ctf,无 test.dll)。但我不知道如何将test.ctf编译成main.cpp?
有人可以帮助我吗?
谢谢。
all
I have test.m( matlab source code) file which implement A() function; and main.cpp file (will call A() ).
as you know ,we may do like the following steps:
use matlab to compile test.m (mcc -) ,will generate : test.dll, test.ctf,test.h .
copy the test.dll and test.ctf ,test.h file to VS2005 project. in main.cpp, call A() in test.dll.
But,when i release the programe,i will also pack the test.dll together.
And another way, can i using the VS2005 to compile both test.m and main.cpp which will only generate main.dll,main.ctf,main.h..( i will only release main.dll,main.ctf,main.h,).
this means, i compile the test.m into main.cpp.
And i have tried this way, in VS2005 ---> Build Events--> pre-Build Event-->command line: mcc C -w lib:test test.m
and it will generate the mid-file test.ctf(only test.ctf,no test.dll).But i don't know how to compile test.ctf into main.cpp ?
could anyone help me ?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以以相反的方式执行此操作,并将 main.cpp 添加到 matlab 构建过程中:我不知道确切的语法,但您可以将 main.cpp 添加到 mcc/mbuild,它会将其添加到 dll为你。在gui模式下使用deploytool时,只需将c/c++文件拖到资源区,它们就会被编译到dll中。因此,您将拥有一个仅包含 m 代码和您自己的 c++ 代码的 dll。
另一种选择,使用上述策略:首先尝试上述方法,然后查看deploytool的输出:它会向您显示所使用的命令。首先它调用 mcc,然后 mbuild 又调用 cl(MS 编译器)。使用用于调用 mcc 作为预构建事件的确切命令,然后以与 mbuild 相同的方式将该输出文件添加到 cl (您还可以在输出中看到它是如何做到这一点的)。这样你就可以使用 VS 构建单个 dll,只需模仿 matlab 构建过程的作用即可。
我仍然不确定这比单独分发两者有什么好处。另外,不要忘记您必须将整个 MCR 与它一起分发,否则您的客户端将无法使用该 dll 运行任何代码。
You can do it the other way around and add your main.cpp to the matlab build process: I don't know the exact syntax, but you can add your main.cpp to mcc/mbuild, and it will add it to the dll for you. When using deploytool in gui mode, just drag c/c++ files to the resources area and they get compiled into the dll. So you'll have one dll only containing both m code and your own c++ code.
Another option, using the above strategy: first try the above, and look at the output of deploytool: it will show you the commands used. First it invokes mcc, then mbuild which in turn calls cl (the MS compiler). Use the exact command used to invoke mcc as a pre-build event, and then add that output files to cl in the same way mbuild does it (you can also see in the output how it does that). This way you can use VS to build a single dll anyway, just mimick what the matlab build process does.
Still I'm not sure how this is beneficial over distributing the two seperately. Also don't forget you have to distribute the entire MCR with it else your clients won't be able to run any code using the dll.