主题:[原创](要求置顶)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上使用通过。
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上使用通过。