compiling/mexing imrender 函数在 Matlab 中使用 OS X 时出错

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

我正在尝试在 Matlab 中使用 Oliver Woodford 的 imrender_v2.4.zip (http://www.robots.ox.ac.uk/~ojw/software.htm) 中的特定函数,特别是 vgg_qpbo 函数。

相关文件应该识别 mex-file 不存在并编译一个。

但是,在 运行宁 startup.m 并尝试类似

>> vgg_qpbo(1,1,1)

我明白了

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

我一直在努力找出问题所在。 主要怀疑是 Mac OS X (Yosemite 10.2) 我是 运行ning,因为它可以在 Linux 版本上编译(不知道哪个,但我可以找出你是否认为它相关)我的主管使用过。它不是我的电脑独有的,因为我们在另一台 mac 上尝试过,结果完全相同。

我认为这些警告是可以忽略的,因为它们只是警告(我不精通 C++,但我认为这是一个相对较新的警告,但不应该影响编译本身)。

我也试过找出脚本中错误发生的位置,但 mexing-part 肯定是开始了,比那更进一步我觉得不舒服。

我以前在这台电脑上混合过其他脚本,我可以 运行 例如

>> mex -setup

一帆风顺。

那么有人知道问题出在哪里吗?感谢您的宝贵时间!

顺便说下我是运行宁Matlab R2014B

编辑

所以我听从了lilbill39的建议,在调用mexing的那行打了一个断点(vgg_mexcompile中的第74行)然后运行

eval(cmd)

从命令行。

这导致了 36 个新警告、23 个注释和 4 个错误。

错误都是相似的,但在不同的行上:

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)

在这 4 个错误中的每一个之后,都会出现相同类型的注释:

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

还有一种笔记(一共29个):

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

内箭头不同类。

大部分警告都是相同的

conversion from string literal to 'char *' is deprecated

-警告和以前一样。而有些是

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

混合数字格式。

因此 QPBO 中的四个地方似乎需要 "implicit instantiation"。cpp-file(假设可以再次忽略所有警告)。通过快速 google 搜索,我了解到它与文件的 "linking" 有关,但是已经很晚了,明天必须继续搜索。当然,在此之前提供更多帮助将不胜感激!

我无法验证这是否是适合您的解决方案,因为它在我使用 VS2012 的机器上编译得很好,但我的建议是将实例化移到专业化的声明和定义下方。编辑 instances.inc 并移动以下行:

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

到文件底部(在专业化下方)。

参见this answer for an explanation