回 帖 发 新 帖 刷新版面

主题:[原创](要求置顶)BCB 如何调用matlab生成的lib/dll

How to Compile MATLAB File to BCB File:
Step 1: Write .m file in matlab.
            i.e. : function M = myfunction(a,b)
             M = a * b ;
           save as A.m

Step 2: Set compile environment
   Enter mex -setup and mbuild -setup then select which compiler you’ll use.

Step 3: Compile .m to .dll
    Enter mcc -B csglsharedlib:mydll  A.m [B.m] […]
    This command will generate all files by BCB needed, such as mydll.cpp, mydll.h, mydll.dll and mydll.lib etc.

Step 4:Add the following two into “project-options-Directories/Conditionals” :
     include: Matlab\extern\include
     library:Matlab\extern\lib\win32\borland\bc50
                  Matlab\bin\win32
   Add #include “mydll.h” to your file

Step 5: Add the needed lib to your project :
     Add mydll.lib,  Matlab\extern\lib\win32\borland\bc54\mclmcrrt.lib 
               and OTHER lib file you needed into “project-Add to project”.
Step 6 : In project-options-linker
               - linking page unselect “Use dynamic RTL”.
Step 7:
   if(!mclInitializeApplication(NULL,0))
  {   return ERROR_MESSAGE;  }
 if(!YourBCB_MatlabInitialize())
  {  return ERROR_MESSAGE; }
Step 8: call your matlab function,
Step 9:When finished,call the following function:
  MydllTerminate();
 mclTerminateApplication();

以上步骤在BCB6.0+Matlab 7.0上使用通过。

回复列表 (共14个回复)

11 楼

Matlab 7在执行第三步时可能会出现错误,解决办法如下:
Warning: No matching builtin function available for $MATLAB/toolbox/simulink/simulink/set_param.bi
To resolve this issue, you should modify the following file:
$MATLAB/toolbox/compiler/deploy/matlabrc.m
(where $MATLAB = the MATLAB root directory on your machine)
Comment out the following lines (numbers 81 and 82) that have a call to SET_PARAM.
  set_param(0,'PaperType',defaultpaper);去掉这两行
  set_param(0,'PaperUnits',defaultunits);
When you are finished, save these changes and issue the following command at the MATLAB command prompt:
rehash toolboxcache

12 楼


第三步你是怎么搞定的呀?我也与到这问题了

13 楼

请问我也遇到第三步过不了,怎么回事呀?谢谢

14 楼

最近又有人问我这个调用问题,所以把这个帖子顶起来,希望对大家能有帮助。

我来回复

您尚未登录,请登录后再回复。点此登录或注册