回 帖 发 新 帖 刷新版面

主题:[原创](要求置顶)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个回复)

沙发

Step 3: Compile .m to .dll
这一步好象实现不了.

板凳

请问一下:在使用你的第三步的时候会出现如下的错误:
Turbo Incremental Link 5.60 Copyright (c) 1997-2002 Borland 
Fatal: Could not open _lib4368.def (error code 2) 
 
  MBUILD.BAT: Error: Link of 'mydll.dll' failed. 
 
??? Error using ==> mbuild
Unable to complete successfully

??? Error: An error occurred while shelling out to mbuild (error code = 1).
Unable to build executable (specify the -v option for more information).

Error in ==> D:\matlab6.5\toolbox\compiler\mcc.dll
这些错误是什么意思,该怎样做能消除错误.

3 楼

第三步我已经搞定了,
但现在不知道第七步的程序该放在什么地方.还有第八步也不知道该怎么做.

4 楼

step 7放在程序初始化的地方,
step 8就像其他函数一样调用,你在左侧的资源窗口里可以看到那些函数名称的,所有的函数名称会被重命名成如下:mlfYourFuncName(),你可以直接调用的。
Do remember:这里函数的参数都是数组类型的,操作如下:
    double dDefaultU= 1234;
    mxArray *mxDftU=mxCreateDoubleMatrix(1, 1, mxREAL);//开辟一个1x1的数组
    mxSetPr(mxDftU,&dDefaultU);//数组赋值
    mlfYourFuncName(mxDftU,…);

5 楼

我觉得好象要在BCB中的窗口上添加一个按扭,
你的步骤上怎么没有啊.
应该在哪一步添加?添加后的程序是什么?
第八步,我还是不知道该怎么调用,能不能告诉我具体的步骤.
谢谢.

6 楼

void __fastcall TFormMain::btnPeak2PeakClick(TObject *Sender)
{ //Peak2Peak
  mlfPeak2peak(Y,U,V,data_file_select);
}

7 楼

唉,这么好的东西咋就没人看呢?

8 楼

唉,这么好的东西咋就没人看呢?坚决顶上去。

9 楼

if(!YourBCB_MatlabInitialize())
   

请问,这句命令是什么意思?
对matlab初始化?...

10 楼


对,就是对matlab进行初始化,已经在邮件中作了回复,请查收。

我来回复

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