Search code examples
c++macosmatlabmex

Error when compiling/mexing imrender function with OS X in Matlab


I am trying to use a specific function in Oliver Woodford's imrender_v2.4.zip (http://www.robots.ox.ac.uk/~ojw/software.htm) in Matlab, specifically the vgg_qpbo function.

The related files are supposed to recognize that a mex-file does not exist and compile one.

However, after running startup.m and trying something like

>> vgg_qpbo(1,1,1)

I get

Warning: Missing MEX-file: vgg_qpbo. Will attempt to compile and run. 
 > In vgg_mexcompile_script at 25
  In vgg_qpbo at 84 
mex -O -I"/Users/.../imrender/vgg" "-Iqpbo/" "vgg_qpbo.cxx" "qpbo/QPBO.cpp" "qpbo/QPBO_maxflow.cpp" "qpbo/QPBO_extra.cpp" "qpbo/QPBO_postprocessing.cpp"
Building with 'Xcode Clang++'.
In file included from /Users/.../imrender/vgg/vgg_qpbo.cxx:11:
In file included from qpbo/QPBO.h:116:
qpbo/block.h:124:56: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
                            if (!next) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
                                                                               ^
qpbo/block.h:223:56: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
                    if (!first) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
                                                                        ^
2 warnings generated.

ERROR while compiling vgg_qpbo
Error using vgg_mexcompile_script (line 30)
Unable to compile vgg_qpbo.

Error in vgg_qpbo (line 84)
vgg_mexcompile_script; % Compilation happens in this script

I have been trying to figure out what is the problem. The main suspect is the Mac OS X (Yosemite 10.2) I am running, as it is compilable on a Linux version (do not know which, but I could find out if you think it is relevant) my supervisor used. It is not exclusive to my computer as we tried it on another mac with the exact same result.

I believe the warnings are ignorable as they are just warnings (I am not savvy in C++, but I gathered that it is a relatively new warning, but should not affect the compilation itself).

I have also tried figuring out where in the scripts the error occurs, but the mexing-part is definitely starting, and further than that I do not feel comfortable to go.

I have mexed other scripts on this computer before and I can run for example

>> mex -setup

without a hitch.

So does anyone know what the problem might be? And thank you for your time!

I am running Matlab R2014B by the way.

EDIT

So I followed lilbill39's suggestion and put a breakpoint at the line that calls the mexing (line 74 in vgg_mexcompile) and then ran

eval(cmd)

from the command line.

This resulted in 36 new warnings, 23 notes and 4 errors.

The errors are all alike but on different lines:

qpbo/instances.inc:19:29: error: explicit specialization of 'get_type_information' after instantiation
    inline void QPBO<int32_t>::get_type_information(char*& type_name, char*& type_format)

After each of these 4 errors the same type of note follows:

/Users/.../imrender/vgg/qpbo/QPBO.cpp:277:3: note: implicit
instantiation first required here
            get_type_information(type_name, type_format);
            ^

There was one other kind of note (29 of these in total):

qpbo/instances.inc:15:16: note: in instantiation of member function  'QPBO<float>::Save' requested here
template class QPBO<float>;
           ^

With different classes within the arrows.

Most of the warnings were the same

conversion from string literal to 'char *' is deprecated

-warnings as before. Whereas some were of the type

format specifies type 'int' but the argument has type 'long long'

with mixed number formats.

So it would seem that an "implicit instantiation" is needed in four places in the QPBO.cpp-file (assuming all warnings can be ignored yet again). With a quick google search I gathered that it has something to do with the "linking" of the files, however it is getting late and will have to continue searching tomorrow. More help until then would of course be greatly appreciated!


Solution

  • I can't verify this as a solution for you because it compiles fine on my machine with VS2012, but my suggestion would be to move the instantiations below the declarations and definitions of the specializations. Edit instances.inc and move the following lines:

    // Instantiations
    template class QPBO<int32_t>;
    template class QPBO<int64_t>;
    template class QPBO<float>;
    template class QPBO<double>;
    

    to the bottom of the file (below the specializations).

    See this answer for an explanation.