mex compliation problem with include paths for file mexopts.bat

HI,
I am really very Frustrated of doing mex stuff, I am trying for more than 3 Days I know there is very little thing that need to be done to make mex displayImage.cpp to work
I have installed VS10, SDK7.1, MAtlab2012a,opencv 2.3, Everything is fine
Also I am not able to run mex-setup again it giving me following error
mex-setup
Usage:
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
Use the -help option for more information, or consult the MATLAB API Guide.
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: No file names given.
Undefined function or variable 'setup'
and if I run the cpp File it gives me following error
mex displayImage.cpp
displayImage.cpp
displayImage.cpp(5) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
even stdio.h is inside the folder of my current working Directory.
Looking forward....
Thanks and regards

댓글 수: 15

Try mex -setup (there is a space before the hyphen).
thanks for this correction but now I am still getting this error Please can you tell me how to set all the procedure to accomplish mex compilation, the error
mex -setup
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012a/win32.html
Please choose your compiler for building 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\R2012a\sys\lcc
[2] Microsoft Software Development Kit (SDK) 7.1 in C:\Program Files\Microsoft Visual Studio 10.0
[3] Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0
[0] None
Compiler: 3
Please verify your choices:
Compiler: Microsoft Visual C++ 2010
Location: C:\Program Files\Microsoft Visual Studio 10.0
Are these correct [y]/n? y
*************************************************************************
Warning: MEX-files generated using Microsoft Visual C++ 2010 require
that Microsoft Visual Studio 2010 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************
C:\Program Files\Microsoft Visual Studio 10.0
Error using mex (line 206)
Unable to complete successfully.
Moreover, if i run displayImage.cpp file do you have any idea how to do this for opencv
mex displayImage.cpp it gives following error
mex displayImage.cpp
displayImage.cpp
displayImage.cpp(7) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
@Kaustubha Govind, Also I am giving path in mexopts.bat is given below
set OPENCVDIR=C:\opencv;
set LIB=%OPENCVDIR%\build\x86\vc10\lib;
set PATH=%OPENCVDIR%\build\x86\vc10\bin;
set INCLUDE=%OPENCVDIR%\include\opencv\cvaux;
set INCLUDE=%OPENCVDIR%\include\opencv\cv;
set INCLUDE=%OPENCVDIR%\include\opencv\cxcore;
set INCLUDE=%OPENCVDIR%\include\opencv\highgui;
set INCLUDE=%OPENCVDIR%\include\opencv\cvcam;
and set LINKFLAGS=/dll /export:%ENTRYPOINT% /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib cv.lib cvaux.lib cxcore.lib cxcore.lib highgui.lib cvcam.lib /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"%LIB_NAME%.x" /MAP:"%OUTDIR%%MEX_NAME%%MEX_EXT%.map"
all this is in the guideline given in the mathworks website, I tried to do as it is and Environment variable I set is OPENCVDIR C:\opencv\build
and Path Variable is edited as %OPENCVDIR%\build\x86\vc10\bin
I dont where I am wrong ????
Could you try mex displayImage.cpp -IC:\opencv (assuming that C:\opencv is where cv.h is present).
@Kaustubha Govind, I did this
mex displayImage.cpp -l C:\opencv
displayImage.cpp
displayImage.cpp(7) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
infact I want to use opencv functions in matlab is there anyother option to use them without mex. mex is hell hardcoded thing I dont how I can get out of this Problem, hope you are having some solutions
@Muhammad: Kaustubha asked you to try:
mex displayImage.cpp -IC:\opencv
You have tried:
mex displayImage.cpp -l C:\opencv
Do you see the difference?
@Jan Simon, I have tried all possible ways, problem is somewhere else please have a look at my configuration in previous comments
mex displayImage.cpp -lC:\opencv
displayImage.cpp
displayImage.cpp(7) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
Still not what you were asked for. There is a big difference between
-lC:\opencv
and
-IC:\opencv
Please try it again correctly with
-IC:\opencv
@Muhammad: "l" is a lowercase L, "I" is an uppercase "i".
@Jan, So its 'i' Capital , this is also giving same result, @Jan, I think Problem is with include paths or somewhere else, this is error
mex displayImage.cpp -IC:\opencv
displayImage.cpp
displayImage.cpp(7) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
@Jan, also This is the code of displayImage.cpp
/******************************************************************* This is a simple MEX file. It just calls OpenCV functions for loading, smothing and diaplaying the results ******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <highgui.h>
#include "mex.h"
int smoothImage(char* filename){
//load the image
IplImage* img = cvLoadImage(filename);
if(!img){
printf("Cannot load image file: %s\n",filename);
return -1;}
//create another image
IplImage* img_smooth = cvCloneImage(img);
//smooth the image img and save the result to img_smooth
cvSmooth(img, img_smooth, CV_GAUSSIAN, 5, 5);
// create windows to show images
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
cvMoveWindow("Original Image", 100, 100);
cvNamedWindow("Smoothed Image", CV_WINDOW_AUTOSIZE);
cvMoveWindow("Smoothed Image", 400, 400);
// show the images
cvShowImage("Original Image", img );
cvShowImage("Smoothed Image", img_smooth );
// wait for a key
cvWaitKey(0);
//destroy windows
cvDestroyWindow("Original Image");
cvDestroyWindow("Smoothed Image");
//release images
cvReleaseImage(& img);
cvReleaseImage(& img_smooth);
return 0;};
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
if (nrhs != 0){
mexErrMsgTxt("Do not give input arguments.");}
if (nlhs != 0){
mexErrMsgTxt("Do not give output arguments.");}
char *name = "cameraman.png";
smoothImage(name);}
@Jan Simon, @Kaustubha Govind, what you think Finally I am thinking to reinstall VS10 and matlab, is there any Suggestion from you ???
one thing I have seen that when I run mex -setup then it wipe out all paths that are newly added to it, and therefore it can not find cv.h or else things
Jan
Jan 2013년 8월 30일
편집: Jan 2013년 8월 30일
Please test, if cv.h is where you expect it:
exist('C:\opencv\ch.h', 'file')
Try the quotes instead of < and >:
#include "cv.h"

댓글을 달려면 로그인하십시오.

답변 (2개)

turab
turab 2013년 8월 30일
i have the exact same problem. i have also read on a page that matlab 2012a and visual studio 2010 donot support initially there is a patch for this purpose i have downloaded this patch and placed in the matlabroot but the problem remains the same the error i am constantly getting is : mex displayimg.cpp Error: Could not find the compiler "cl" on the DOS path. Use mex -setup to configure your environment properly.
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Unable to locate compiler.
plz give me some helpful suggestions thanx.

댓글 수: 2

This error is unrelated to what Muhammad is reporting -- I recommend you begin a new topic.
@turab, please read the comment of Kaustubha Govind carefully.

댓글을 달려면 로그인하십시오.

Ken Atwell
Ken Atwell 2013년 8월 30일
편집: Jan 2013년 8월 30일
I would not reinstall MATLAB or Visual Studio; you have a path problem that reinstalling will not solve.
Are you sure cv.h is in C:\opencv, and not a subfolder under it? I am not familiar with OpenCV, but I would try:
mex -IC:\opencv\include\opencv displayImage.cpp
If that fails, open the Explorer and locate the name of the folder where cv.h is found. Wherever that is, put that folder name (not filename) as the -I parameter to MEX.
And, yes, if you rerun "mex -setup", it will clobber any customization you may have made to mexopt.bat. In general, I would only edit this file as a last resort.

댓글 수: 5

@Ken Atwell, your answer is very Logical it should solve the problem, I can show what I got , I Have tried from two different Path to access ch.h, it is accessing it but Still some problem, i am so sorry lot of troubleshooting could not solve it,
mex -IC:\opencv\opencv\include\opencv displayImage.cpp
displayImage.cpp
C:\opencv\opencv\include\opencv\cv.h(63) : fatal error C1083: Cannot open include file: 'opencv2/core/core_c.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
>> mex -IC:\opencv\build\include\opencv displayImage.cpp
displayImage.cpp
C:\opencv\build\include\opencv\cv.h(63) : fatal error C1083: Cannot open include file: 'opencv2/core/core_c.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
These message mean, that you've found two cv.h files successfully:
  1. C:\opencv\opencv\include\opencv\cv.h
  2. C:\opencv\build\include\opencv\cv.h
Is it correct, that there are duplicates of this file? Perhaps the OpenCV installation is damaged?
But now the compiler cannot find opencv2/core/core_c.h... You can search for the folder "opencv2/core". I assume, your trials to solve the original problem produced some problems.
@Jan Simon, Its the Structure of opencv that it distributes its folder in the above mentioned hierarchy, I have seen opencv2 folder and it includes the specified files, When I give opencv2 in path then i could not find cv.h, if I give cv.h then i can not find core_c.h please have a look, I am missing some path somewhere
>> mex -IC:\opencv\opencv\build\include\opencv2 displayImage.cpp
displayImage.cpp
displayImage.cpp(7) : fatal error C1083: Cannot open include file: 'cv.h': No such file or directory
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'displayImage.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
@Jan Simon, @Ken Atwell, is there still anything that I can do???
Also My Opencv with Visual Studio 10 Is working fine I have run an example but with matlab problem is not getting solved

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

질문:

2013년 8월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by