MEX compilation error with included paths

Hello, I am having a problem trying to compile a *.cpp file.
I have VisualStudio 2015, OpenCV 3.1.0, Matlab 2016a
Every time I try to create a MEX file I get a similar error.
When I run:
mex mex_main.cpp
I get the following error:
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
mex_main.cpp
C:\...\mex_main.cpp(20): fatal error C1083:
Cannot open include file: 'cv.h': No such file or directory
Following other examples, I modified the mex function
mex mex_main.cpp -I'C:\opencv\build\include\opencv' -I'C:\opencv\build\include\opencv2'
to include the directories where 'cv.h' is. But I keep having a similar problem.
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
mex_main.cpp
C:\opencv\build\include\opencv\cv.h(63): fatal error C1083: Cannot open include file: 'core_c.h': No such file or
directory
And the problem persists even if I add those directories.
mex mex_main.cpp -I'C:\opencv\build\include\opencv' -I'C:\opencv\build\include\opencv2' I'C:\opencv\build\include\opencv2\core'
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
mex_main.cpp
C:\opencv\build\include\opencv2\core\core_c.h(48): fatal error C1083: Cannot open include file: 'opencv2/core/types_c.h':
No such file or directory
Any idea of how can I fix this problem?
Thank you

2 Kommentare

Jan
Jan am 1 Feb. 2017
Did you forget the "-" before "I'C:\opencv\build\include\opencv2\core'" in the last code?
Saul Armendariz
Saul Armendariz am 1 Feb. 2017
Yes, I am sorry. I accidentally delete the '-' while giving format to the text. The entry code contained the '-'

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 1 Feb. 2017

0 Stimmen

Does this help:
-I'C:\opencv\build\include\'
?

3 Kommentare

Hi Jan
Thank you for taking the time to answer my question.
I tried with the following code:
mex mex_main.cpp -I'C:\opencv\build\include' -I'C:\opencv\build\include\opencv' -I'C:\opencv\build\include\opencv2' -I'C:\opencv\build\include\opencv2\core'
But I am still getting a similar error:
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
mex_main.cpp
C:\opencv\build\include\opencv\cv.h(64): fatal error C1083: Cannot open include file: 'imgproc_c.h': No such file or
directory
The 'imgproc_c.h' file is located in 'C:\opencv\build\include\opencv2\imgproc', so if I add that directory to the code I get a very similar error.
mex mex_main.cpp -I'C:\opencv\build\include' -I'C:\opencv\build\include\opencv' -I'C:\opencv\build\include\opencv2' -I'C:\opencv\build\include\opencv2\core' -I'C:\opencv\build\include\opencv2\imgproc'
and the error:
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
mex_main.cpp
C:\opencv\build\include\opencv\cv.h(65): fatal error C1083: Cannot open include file: 'photo_c.h': No such file or
directory
Does this mean I need to add every single folder inside 'C:\opencv\build\include\opencv2'?
Jan
Jan am 1 Feb. 2017
Bearbeitet: Jan am 1 Feb. 2017
Well, this sounds annoying. But try it:
List = dir('C:\opencv\build\include\opencv2');
Folder = {List([List.isdir]).name};
Other = {'C:\opencv\build\include', ...
'C:\opencv\build\include\opencv', ...
'C:\opencv\build\include\opencv2'};
Arg = strcat('-I', cat(2, Folder, Other));
mex('mex_main.cpp', '-O', Arg{:});
Are the quotes required around the folders? Then:
Arg = strcat('-I''', Folder, char(39));
(char(39) because '''' confuses me).
Sigh. If this works, you do not have to do this manually at least. But actually I'd expect that there is an easier way.
How are the file included? With #include "." or #include < . >?
Hi, I tried to again using your example, unfortunatly, I am still having the same problem.
I tried adding every single folder into the code. Sadly, I am still unable to create the MEX file, this time I get a different error.
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
mex_main.cpp
C:\...\mex_main.cpp(27): error C3861: 'mxArr_to_new_CvMat': identifier
not found
C:\...\mex_main.cpp(33): error C3861: 'CvMat_to_new_mxArr': identifier
not found
The files in the *.cpp file are included with #include < . >.
The file I am trying to run is an example taken from here . I have tried to create the MEX file following the instruction but the original error persist.
Any idea what is causing this?

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 1 Feb. 2017

Kommentiert:

am 3 Feb. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by