-1

I am using MATLAB on the Linux MINT. I have a C program for which I want to used mex command as follows:

mex /home/.../binary.c -output binary_m

but I get the following error

Warning: You are using gcc version "4.8.1-10ubuntu9)".  The version
         currently supported with MEX is "4.4.6".
         For a list of currently supported compilers see: 
         http://www.mathworks.com/support/compilers/current_release/

/home/.../binary.c:43:19: fatal error: binary.h: No such file or directory
 #include "binary.h"

                   ^
compilation terminated.

    mex: compile of ' "/home/.../binary.c"' failed.

I think that I have to downgrade the gcc compiler on the MATLAB but I don't know how.

Any help is appreciate it. Regards

Jonathan H
  • 7,591
  • 5
  • 47
  • 80
user42037
  • 39
  • 7
  • Check if you can compile one of the example files (e.g. `yprime.c`). A warning should not halt execution (and you can always turn it off), so this may be two different things - a warning about compiler version and an error - possibly because `binary.h` is not on the MATLAB path. – nkjt Oct 24 '14 at 10:29
  • Thank you. I also put the header (binary.h) but still the following error, regarding to the gcc version, remains Warning: You are using gcc version "4.8.1-10ubuntu9)". The version currently supported with MEX is "4.4.6". For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release/ /home/.../binary.c: In function ‘mexFunction’: /home/.../binary.c:139:9: warning: assignment from incompatible pointer type [enabled by default] msg = (unsigned char **)mxGetPr(prhs[0]); ^ – user42037 Oct 24 '14 at 11:51
  • 2
    You must differentiate between a **warning** and an **error**. A warning just informs you of a possible problem - in this case, that your compiler version is newer then MATLAB supports and therefore there might be some problems because they haven't tested it (or it might be fine, of course). – nkjt Oct 24 '14 at 13:03

1 Answers1

0

This has nothing to do with the warning regarding the compiler version; don't pay attention to that, you will be fine. You might have had problems trying to compile c++11 sources, depending on your Matlab version, compiler version and mex command flags, but this is not your case.

Here is the problem: your C program binary.c contains an #include statement of the file binary.h which is not found by Matlab (although I trust you put it in the same directory than the C file?) because the directory that contains your C sources is not in the Matlab path.

To fix the problem, simply change directory to where binary.c is, and mex your file there. You can automate the process doing something like:

source_dir  = '/home/.../';
current_dir = fileparts(mfilename('fullpath'));

cd source_dir;
% do something
cd current_dir;
Jonathan H
  • 7,591
  • 5
  • 47
  • 80
  • Thank you. I also put the header (binary.h) but still the following error, regarding to the gcc version, remains Warning: You are using gcc version "4.8.1-10ubuntu9)". The version currently supported with MEX is "4.4.6". For a list of currently supported compilers see: mathworks.com/support/compilers/current_release /home/.../binary.c: In function ‘mexFunction’: /home/.../binary.c:139:9: warning: assignment from incompatible pointer type [enabled by default] msg = (unsigned char **)mxGetPr(prhs[0]); ^ – user42037 Oct 24 '14 at 14:09
  • How in the world do you suspect a version conflict from that message? What is the output type of `mxGetPr`? Hint: http://www.mathworks.co.uk/help/matlab/apiref/mxgetpr.html. The compiler throws a warning because of what you wrote, not because of a version conflict. – Jonathan H Oct 24 '14 at 14:27
  • Actually, I have a C file and also it mex file but its mex file is created in windows 64 and 32. So they are not working in Linux. That is why 1- I am 100% sure that the C code is OK 2- I want to create the mex file in Linux 3- the problem is related to the compiler on MATLAB – user42037 Oct 24 '14 at 14:33
  • Ok, let's do this: post a new question with a minimal code of your problem, just a simple C-mex file in which you extract the inputs as you are doing, and which throws the same warning. I'll correct the C code, and you can mark both questions as solved. Deal? – Jonathan H Oct 24 '14 at 14:54