mex unable to find an include file

6 vues (au cours des 30 derniers jours)
Theo
Theo le 26 Juil 2015
Commenté : Theo le 26 Juil 2015
I'm trying to use mex to compile a file, but it does not seem to be able to find an include file. I am using the test file yprime.c found in matlabapplicationfolder/extern/examples/ folder. The code compiles fine when I type
mex yprime.c
However, I now change the first few lines of the code to include a mpfr include file:
#include <math.h>
#include <mpfr.h>
#include "mex.h"
and I try:
mex 'yprime.c' '-I/usr/local/include/ -L/usr/local/lib/ -lmpfr'
It gives me the error
Error using mex
/Users/username/prog/yprime.c:17:10: fatal error: 'mpfr.h' file not found
#include <mpfr.h>
^
1 error generated.
I indeed have:
/usr/local/include/mpfr.h
/usr/local/lib/libmpfr.4.dylib
/usr/local/lib/libmpfr.a
/usr/local/lib/libmpfr.dylib
/usr/local/lib/libmpfr.la
The permissions on all of these are set to 755. I am running OSX 10.10.4. mex -setup returns:
MEX configured to use 'Xcode with Clang' for C language compilation.
  2 commentaires
Walter Roberson
Walter Roberson le 26 Juil 2015
Perhaps try
mex yprime.c -I/usr/local/include/ -L/usr/local/lib/ -lmpfr
Theo
Theo le 26 Juil 2015
It does work! Can you comment as an answer? Also, the reason why I tried the quotation marks was because I was told to do as follows:
mex('yprime.c', '-I/usr/local/include/ -L/usr/local/lib/ -lmpfr')
which is useful if the filenames are specified as Matlab strings in variables. However this syntax does not work! I've tried all the combinations I can think of to call with mex(). How would you call the mex function with variable input?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Juil 2015
Perhaps try
mex yprime.c -I/usr/local/include/ -L/usr/local/lib/ -lmpfr
As a function call this would be
mex('yprime.c', '-I/usr/local/include/', '-L/usr/local/lib/', '-lmpfr')
  1 commentaire
Theo
Theo le 26 Juil 2015
Works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by