Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28450 Discussions

Matlab calls IVF dll generated by IDE environment

Hi I have not found detailed steps to build fortran dll from IDE environement and link to Matlab. I found that IDE approach to create fortran dll is simpler tha "mex -setup " approach since we need to edit *.stp, *.bat files fom /bin & matlab prefdir. We do not have write permission for folder anyway! Hence I created some sample document to create and run visula studio here: I use Vista business SP2, Matlab R2006b, IVF 11.0 & VS 2008. ===================================================================== 1. Create Fortran Project from IDE: File->New Project->IVF->Library->Dynamic-link Library: Project name : 2. Copy \extern\include\mexversion.rc to the local project dir: TestIVFDLL 3. Solution explorer->Resource Files->Add existing item->mexversion.rc 4. Copy sample mexfunction fortran file from >matlabroot>\extern\reffbook\timestwo.F to the local project dir TestIVFDLL 5. Solution explorer->Source Files->Add existing item->timestwo.F 6. Solution explorer->Fortran->General->Additional Include Directories: \extern\include 7. Solution explorer->Fortran->Preprocessor: Yes(/fpp) 8. Solution explorer->Fortran->Diagnostics: Generate Interface Blocks: No Check Routine Interface : No 9. Solution explorer->Linker->General->Output Files: .mexw32 10. Solution explorer->Linker->General->Output FilAdditional Include Directories: \extern\lib\\microsoft (Here it is Vista 32-bit platform) 11. Solution explorer->Linker->Input->additional dependencies : libmx.lib libmex.lib libmat.lib libeng.lib 12. Solution explorer->Linker->Input->Module definition file: "myModule.def" For this case: %%%%%%%%%%%%%%%%%%%%%%%%% LIBRARY TestIVFDLL EXPORTS MEXFUNCTION TIMESTWO %%%%%%%%%%%%%%%%%%%%%%%%% 13. Issue Build command. After build, perform the following check: ========================================= 1. Go to command prompt; go to project dir & issue DUMPBIN command. (If this command does not work, look for "vcvars.bat" and set all MSVS variables.) $>DUMPBIN /exports .\Debug\testivfdll.mexw32 DUMPBIN command results: ... 1 0 00001005 MEXFUNCTION = @ILT+0(_MEXFUNCTION) 2 1 0000100A TIMESTWO = @ILT+5(_TIMESTWO) ... Everything is perfect: gateway function (MEXFUNCTION)& our calculation function (TIMESTWO) get exported. 2. Construct header file for this function: From fortran: ... subroutine timestwo(y, x) real*8 x, y C y = 2.0d0 * x return end Note: The above file is the the same as \extern\examples\refbook\timestwo.F The corresponding header required for Matlab: void TIMESTWO (double*, double*); -----> otherwise Matlab cribs! 3. Go to Matlab folder and copy the header file & testivfdll.mexw32 4. Write Matlab dummy file to test this dll function dummy() % % matlab is case-sensitive to dll & header names % loadlibrary('testivfdll', 'TestIVFDLL.h'); mlfunc = libfunctions('testivfdll','-full'); libfunctionsview testivfdll aa = 3.0; cc = 0.0; if libisloaded('testivfdll') bb =calllib('testivfdll', 'TIMESTWO', cc,aa) end unloadlibrary testivfdll end
0 Kudos
0 Replies