Ahmedserag777 / randomforest-matlab

Automatically exported from code.google.com/p/randomforest-matlab
0 stars 0 forks source link

Compilation Problems with Matlab 2014a on Mac #64

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have a problem to compile the mex files directly from the source, as it is 
recommended in the downloads section for MacOS users. I used 
RF_MexStandalone-v0.02.zip, Matlab R2014a and MacOS 10.9.4.

To do so I installed the latest version of gcc, 4.9.1 via macports, which is 
said to include gfortran.

When run 'make diabetes' in a terminal in the RF_Reg_C I get an output like this
   echo -e  'Compiling diabetes test case'
   -e Compiling diabetes test case
   g++  src/cokus.cpp src/reg_RF.cpp src/diabetes_C_wrapper.cpp -g -fPIC -pg -O2 -lm  -o diabetes_test
and a subsequent test './diabetes_test' suggests that everything works fine.

When I set the compiler for Matlab R2014a by 'mex -setup', I am told that I use 
a 'MEX configured to use 'Xcode with Clang' for C language compilation.' (which 
is probably what I used the last time I compiled anything via Matlab) and can 
choose a different language by 'mex -setup FORTRAN'. This gives me a positive 
output (at least when Matlab is opened from a terminal that 'knows' the path to 
gcc, see here: 
http://www.mathworks.com/matlabcentral/answers/116922-mex-cannot-find-gfortran-c
ompiler-mac-os), but also a warning:
   MEX configured to use 'gfortran' for FORTRAN language compilation.
   Warning: The MATLAB C and Fortran API has changed to support MATLAB
     variables with more than 2^32-1 elements. In the near future
     you will be required to update your code to utilize the
     new API. You can find more information about this at:
     http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.

Sadly, whenever I run any script now, that contains a command with 'mex ... -o 
...', I get the error
   Error using mex
   Unknown MEX argument '-o'.

Also sadly, the recommended 'compiler_settings.txt' in the 
'MacOS_precompiled-WITHOUT_SOURCE-v0.02.tar'-download are of no help to me, 
since they rely on a 'mexopts.sh'-file, which does not exist anymore for this 
version of Matlab.
http://www.mathworks.com/matlabcentral/answers/124597-how-to-setup-gfortran-on-m
ac-osx-10-9-and-matlab-r2014a
For the same reason, I could not apply anything I found so far in the issues 
section.

Any help would be greatly appreciated!
Best regards,
Rosmarie

Original issue reported on code.google.com by rosmarie...@gmail.com on 25 Aug 2014 at 3:49

GoogleCodeExporter commented 8 years ago
hello

what happens if you write mex on matlab's command prompt? and i am guessing 
you're running mex via the command prompt (on running makefile)... what is the 
output if you run mex on command prompt then? 
i am guessing you might not have matlab's mex in the command prompt but some 
other mex command and that's why -o is not being accepted

what you can instead do is
navigate to RF_Reg_C and run the following two commands (do both steps within 
matlab's command prompt)
mex mex_regressionRF_train.cpp reg_RF.cpp cokus.cpp -o mexRF_train -DMATLAB 
mex mex_regressionRF_predict.cpp reg_RF.cpp cokus.cpp -o mexRF_predict -DMATLAB

btw are you using RF_Class_C you'll have to run a different set of commands 
(lines 22 and 23 in 
https://code.google.com/p/randomforest-matlab/source/browse/trunk/RF_Class_C/com
pile_linux.m#22)

Original comment by abhirana on 26 Aug 2014 at 4:49

GoogleCodeExporter commented 8 years ago
Hello abhirana, thanks for your comments.

On typing 'mex', I get
   Error using mex
   Not enough input arguments.
and on 'help mex':
   Contents of mex:
       virtualinport                  - describes the virtual input port block
   Contents of mex:
      rtwmakecfg                     - Add include and source directories to make files.
   mex is both a directory and a function.
   mex   Compile mex-function
   Usage:
        mex [options ...] file [files ...]
    Description:
        ...
    Command Line Options Available on All Platforms:
        ...
        -O
            Optimize the object code. Optimization is enabled by default and
            by including this option on the command line. If the -g option
            appears without the -O option, optimization is disabled.
   ...
    For more information, see
            http://www.mathworks.com/help/matlab/ref/mex.html
    ...
(full output in file attached)

The command documentation matches with the documentation on the original matlab 
support page, but there is really no option -o, only one option -O for 
optimization. Which is, why both the commands you posted, when executed in the '
/Users/Marie/Documents/MATLAB' (where the files listed lay) give the same error.
Did Matlab maybe change the syntax for the mex command?

When I run cc = mex.getCompilerConfigurations i get a 3x1 struct, of which the 
third entry obviously describes the gfortran compiler.

Original comment by rosmarie...@gmail.com on 26 Aug 2014 at 8:01

Attachments:

GoogleCodeExporter commented 8 years ago
Somehow, after all, I wasn't quite sure if I had my compilers and settings in 
Matlab all right. So I started right over again. These were the steps I took, 
and at least I got a working compiler setup, which is at least something:

1) Re-installed Xcode from App-Store

2) Installed latest version of CommandLineTools (OS X 10.9) for Xcode - Late 
August 2014
   from official Developers Website: https://developer.apple.com/downloads/index.action

3) Download the latest precompiled GNU compilers. Xcode includes the GNU C and 
C++ compilers,
   but the versions are sometimes a bit dated. Followed procedure described here:
      https://wiki.helsinki.fi/display/HUGG/Installing+the+GNU+compilers+on+Mac+OS
      +X#InstallingtheGNUcompilersonMacOSX-InstructionsforMacOS10.9(Mavericks)withXcode5
   Copied the file from http://hpc.sourceforge.net to my home folder, then used
    sudo tar xvf gcc-4.9-bin.tar -C /
   to unpack its content to my root directory.
   Then, since my terminal type (echo $SHELL) was /bin/bash, used
    echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
   to ensure the newly installed compilers are used by default. This worked fine, as this output suggests:
    me:~ Marie$ gcc -v
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-
    include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
    Target: x86_64-apple-darwin13.3.0
    Thread model: posix
    me:~ Marie$ gfortran -v
    Es werden eingebaute Spezifikationen verwendet.
    COLLECT_GCC=gfortran
    COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin13.1.0/4.9.0/lto-wrapper
    Ziel: x86_64-apple-darwin13.1.0
    Konfiguriert mit: ../gcc-4.9.0/configure --enable-languages=fortran
    Thread-Modell: posix
    gcc-Version 4.9.0 (GCC) 

4) Since, back in MATLAB, I got this error
    >> mex -setup FORTRAN
    Error using mex
    No supported compiler or SDK was found. For options, visit
    http://www.mathworks.com/support/compilers/R2014a/maci64.
   I followed some advice from this link:
      http://www.mathworks.com/matlabcentral/answers/103904-can-i-use-xcode-5-as-my-c-or-c-
      compiler-in-matlab-8-1-r2013a-or-matlab-8-2-r2013b
    cd(matlabroot)
    cd bin
   Saving a copy of mexopts.sh as ORIGINAL_mexopts.sh
   In the ‘maci64’ section replaced all instances (five) of 10.7 by 10.8,
   since in the terminal I checked that this exists:
    me:~ Marie$ find `xcode-select -print-path` -name MacOSX10.8.sdk
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
    MacOSX10.8.sdk
    me:~ Marie$ find `xcode-select -print-path` -name MacOSX10.9.sdk
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
    MacOSX10.9.sdk
   and the MathWorks SupportTeam in the reference above recommended using the older version.

5) finally, in MATLAB, the test:
    >> mex -setup
   Chose my altered mexopts.sh
    >> copyfile(fullfile(matlabroot,'extern','examples','refbook',...
    'timestwo.c'), fullfile(pwd), 'f');
    >> mex timestwo.c
   Successfully compiled this Matlab test file!

But now back to the randomforest case:
I just assumed that -o should stand for the -output option in the current 
documentation. Is that right?
        >> mex mex_regressionRF_predict.cpp reg_RF.cpp cokus.cpp -output mexRF_predict -DMATLAB
        mex_regressionRF_predict.cpp:82:10: error: no matching function for call to
        'mxCreateNumericMatrix_700'
        plhs[0]=mxCreateNumericMatrix(n_size,1,mxDOUBLE_CLASS,0);
                     ^~~~~~~~~~~~~~~~~~~~~
         /Applications/MATLAB_R2014a.app/extern/include/matrix.h:1440:31: note: 
         expanded from macro 'mxCreateNumericMatrix'
         #define mxCreateNumericMatrix mxCreateNumericMatrix_700
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~
         /Applications/MATLAB_R2014a.app/extern/include/matrix.h:780:46: note: 
         candidate function not viable: no known conversion from 'int' to
         'mxComplexity' for 4th argument
         LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *mxCreateNumericMatrix_700...
                                                      ^
         1 error generated.
         mex: compile of ' "mex_regressionRF_predict.cpp"' failed.
         Unable to complete successfully.
Unfortunately, I have no idea what to do with this error. The same attempt with 
mex_regressionRF_predict.cpp throws a similar, jet longer error message.
I hope at least the first part of the story is conclusive enough to assume that 
at least the compilers installed and the settings in MATLAB should be all right 
now. Is it?

Any ideas for the mex compilation errors?

Original comment by rosmarie...@gmail.com on 26 Aug 2014 at 2:14

GoogleCodeExporter commented 8 years ago
great. i think you're almost there

yup i think i know the mex issues. the 4th variable earlier used to be bool. 
they have changed it to something else.

do this, change
plhs[0]=mxCreateNumericMatrix(n_size,1,mxDOUBLE_CLASS,0);
to
plhs[0]=mxCreateNumericMatrix(n_size,1,mxDOUBLE_CLASS,mxREAL);

if you get any other error let me know

Original comment by abhirana on 26 Aug 2014 at 6:29

GoogleCodeExporter commented 8 years ago
Hey, thats awesome! It just works!

I did the same change that you suggested to every command of the same structure 
in the mex_regressionRF_predict.cpp, mex_ClassificationRF_predict.cpp and 
mex_ClassificationRF_train.cpp, and they all compiled nicely.

Well, nicely - saying with a warning:
   In file included from reg_RF.cpp:65:
   ./qsort.c:80:42: warning: for loop has empty body [-Wempty-body]
                       l--;for(;v[l]>vt;l--);
                                            ^
   ./qsort.c:80:42: note: put the semicolon on a separate line to silence this
         warning
   1 warning generated.

I will attach all the files that I finally used below, so anyone who has a 
similar problem may just follow the steps above and use the files.

Thank you very much, abhirana!

Original comment by rosmarie...@gmail.com on 27 Aug 2014 at 8:41

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Abhi and Rosmarie,

It is awesome. I followed the every single step and finally solved my problem 
with the compiling.
By the way I still receive this message:

         MEX configured to use 'Xcode with Clang' for C language compilation.
         Warning: The MATLAB C and Fortran API has changed to support MATLAB
     variables with more than 2^32-1 elements. In the near future
     you will be required to update your code to utilize the
     new API. You can find more information about this at:
     http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-       api.html.

         To choose a different language, select one from the following:
         mex -setup C++ 
         mex -setup FORTRAN
and when I choose FORTRAN it gives me an error that:

         Error using mex
         No supported compiler or SDK was found. For options, visit 
         http://www.mathworks.com/support/compilers/R2014a/maci64.
but the compiler works seamlessly. 
Do you have any idea that where is the problem?

Regards,
Vadoud

Original comment by vad...@gmail.com on 6 Nov 2014 at 6:41

GoogleCodeExporter commented 8 years ago
you can ignore the warning message about elements, unless if you are using 
really large matrices.

other than that you should be good to go if you are able to run the tutorial 
files are the compilation is done

Original comment by a...@flashbacktechnologies.com on 6 Nov 2014 at 6:47