在 64 位机器上编译 32 位 matlab 应用程序 (c++)
我目前正在 64 位机器上用 C++ 构建一个 32 位 MatLab 引擎应用程序,并安装了 64 位 MatLab。不过,我确实拥有 MatLab 引擎的 32 位 dll 和库文件。库文件和 dll 已正确加载(我可以编译并启动应用程序,而不会出现使用 64 位 dll/lib 时出现的任何错误),但 32 位 dll 显然启动了 64 位 matlab 可执行文件,因此,当我尝试对引擎执行某些操作时,我的程序就会崩溃。有没有一种方法可以让我的应用程序启动 32 位 matlab 可执行文件而不是 32 位可执行文件?
提前致谢!
I am currently building a 32-bit MatLab-engine application in c++ on a 64 bit machine, with 64-bit MatLab installed. However, I do have all the dll's and library files in 32-bit for the MatLab engine. The library files and dll's are loaded correctly (I can compile and start the application without getting any errors I would get when I use the 64-bit dll's/libs), but the 32-bit dll's apparently launch the 64-bit matlab executable, so my program crashes as soon as I try to do something with the engine. Is there a way I can make my application launch the 32-bit matlab executable instead of the 32-bit one?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的,但它非常混乱:在我看来,整个 mbuild/deploytool 系统是一个 cr*p 的一部分。 deploytool.bat 的第一个问题是,尽管有“-win32”选项,但当未从 32 位安装目录调用deploytool 时,该选项没有任何效果。第二个问题是 mbuild 选项是 32 位和 64 位版本共享的,因此必须手动指定它们,否则会使用错误的编译器选项。
以下是我从安装了 VS2010 的 64 位 Windows 机器编译 32 位和 64 位版本时所做的一些事情。
指向正确的编译器选项> 到“configuration”部分下的 prj(见下文),prj 中 32 位安装选项文件配置的 deploytool.bat 的完整路径来构建:
请注意,输出目录等将与32 位和 64 位版本。实际上,如果您必须为多个项目执行此操作,这将变得完全难以管理。所以我有一个 msbuild 脚本来让生活更轻松:基本上在 prj 文件中,我用宏替换所有与平台相关的内容(输出目录、matlab 根目录、选项文件位置),然后让 msbuild 复制 prj 并执行正则表达式查找/替换宏的值取决于平台。这允许对两个平台使用相同的 prj。
更新
在对我们的项目进行了一些重大更改之后,我们发现最终处理 matlab prj 文件的麻烦是不值得的。相反,我们通过直接调用 mcc 并为其提供属于项目的所有文件来极大地简化了一切。这是相关的msbuild代码;为了清楚起见,跳过了一些错误检查:
它需要这些属性:
It is possible, but it's extremely messy: the whole mbuild/deploytool system is a piece of cr*p in my opinion. First problem with deploytool.bat is that, although having a '-win32' option, that has no effect whatsoever when deploytool is not invoked from the 32bit install directory. Second problem is that the mbuild options are shared for 32 and 64 bit versions so they have to be specified manually as else the wrong compiler options are used.
Here are some things I did to compile both 32bit and 64bit from a 64bit windows machine with VS2010 installed.
<param.c.cpp.options.file>
to the prj under the 'configuration` section (see below)options file config in prj:
Note that output dir etc will be the same for the 32bit and 64bit versions. In practice, if you have to do this for multiple projects this becomes totally unmanagable. So I have an msbuild script to make life easier: basically in the prj file I replace everything platform dependent (output dir, matlab root dir, options file location) by macros, then let msbuild copy the prj and do a regex find/replace of the macros with values depending on platform. This allows using the same prj for both platforms.
Update
After a few major changes to our projects we found that eventually the hassle of dealing with the matlab prj files was not worth it. Instead, we greatly simplified everything by invoking
mcc
directly and feed it with all files belonging to a project. Here is the relevant msbuild code; some error checking skipped for clarity:It needs these properties: