Mex compile a C++ code

3 views (last 30 days)
BHAVIN kakani
BHAVIN kakani on 28 May 2011
>> mex -setup Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler: [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2007b\sys\lcc
[0] None
Compiler: 1
Please verify your choices:
Compiler: Lcc-win32 C 2.4.1 Location: C:\PROGRA~1\MATLAB\R2007b\sys\lcc
Are these correct?([y]/n): y
Trying to update options file: C:\Users\hp\AppData\Roaming\MathWorks\MATLAB\R2007b\mexopts.bat From template: C:\PROGRA~1\MATLAB\R2007b\bin\win32\mexopts\lccopts.bat
Done . . .
>> mex yprime.c
C:\PROGRA~1\MATLAB\R2007B\BIN\MEX.PL: Error: 'yprime.c' not found.
??? Error using ==> mex at 208 Unable to complete successfully.
I could not able to compile a simple C code in my matlab. Even after installing Microsoft Visual C++ 6.0 compiler. its showing the above mentioned error. I am new to this topic can anybody help me out regarding it.
  1 Comment
Walter Roberson
Walter Roberson on 28 May 2011
Is yprime.c definitely in your working directory? For example, if you try
!dir yprime.c
does it show the file?

Sign in to comment.

Accepted Answer

Jan
Jan on 28 May 2011
"yprime.c" can be found in the examples folder. Either change into this directory:
cd(fullfile(matlabroot, 'extern', 'examples', 'mex'));
mex -O yprime.c
Or specify the file with the full path:
mex('-O', fullfile(matlabroot, 'extern', 'examples', 'mex', 'yprime.c')
If you do not have write permissions for this folder, copy the C-file to a folder you can access.
This is explained in the section "Building MEX-Files" in the documentation.

More Answers (1)

Jan
Jan on 30 May 2011
Please insert new information by editing your question - sending emails is less efficient and I dislike it, especially if it contains 5MB of data.
From your mail:
mex('-O', fullfile(matlabroot, 'extern', 'examples', 'compiler', 'yprime.c'))
Could Not Find C:\Program Files\MATLAB\R2007b\extern\examples\mex\yprime.exp
Something is confused now: Where does "extern\examples\compiler\" come from? yprime.c is in "extern\examples\mex\" - as in the error message. But then the error message and the shown code do not match?!
I suggest to start from the beginning: Delete the exp and lib files created in different folders, copy yprime.c to a new directory, add it to the Matlab PATH, CD to this directory and try to mex the C-file again. I recommend to use the MSVC compiler, because LCC cannot compile C++ code.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!