【问题标题】:error while compiling with matlab mex使用 matlab mex 编译时出错
【发布时间】:2016-08-01 16:02:57
【问题描述】:

我正在尝试使用 matlab mex 进行编译,但我一直收到此错误:

Warning: You are using gcc version "5.4.0-6ubuntu1~16.04.1)".  The version
     currently supported with MEX is "4.2.3".
     For a list of currently supported compilers see: 
     http://www.mathworks.com/support/compilers/current_release/

In file included from descriptor.h:4:0,
                 from calc_shot.cpp:11:
mesh.h: In function ‘double magnitude(const vec3d<T>&)’:
mesh.h:106:9: error: ‘sqrt’ is not a member of ‘std’
  return std::sqrt((v1.x*v1.x) + (v1.y*v1.y) + (v1.z*v1.z));
         ^
In file included from calc_shot.cpp:11:0:
descriptor.h: At global scope:
descriptor.h:7:57: error: expected class-name before ‘{’ token
 class invalid_mesh_descriptor : public std::logic_error {
                                                         ^
descriptor.h: In constructor ‘invalid_mesh_descriptor::invalid_mesh_descriptor()’:
descriptor.h:9:57: error: expected class-name before ‘(’ token
    explicit invalid_mesh_descriptor() : std::logic_error("Exception invalid_mesh_descriptor caught.") {}
                                                         ^
descriptor.h:9:57: error: expected ‘{’ before ‘(’ token
descriptor.h: In constructor ‘invalid_mesh_descriptor::invalid_mesh_descriptor(const string&)’:
descriptor.h:10:70: error: expected class-name before ‘(’ token
    invalid_mesh_descriptor(const std::string& msg) : std::logic_error("Exception invalid_mesh_descriptor caught: "+msg) {}
                                                                      ^
descriptor.h:10:70: error: expected ‘{’ before ‘(’ token
descriptor.h: In function ‘std::ostream& operator<<(std::ostream&, const vec_descriptor<T>&)’:
descriptor.h:123:45: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘const char [2]’)
       for (size_t k=1; k < d.size(); ++k) s << " " << d(k);
                                             ^
In file included from /usr/include/c++/5/string:52:0,
                 from descriptor.h:5,
                 from calc_shot.cpp:11:
/usr/include/c++/5/bits/basic_string.h:5172:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator<<(basic_ostream<_CharT, _Traits>& __os,
     ^
/usr/include/c++/5/bits/basic_string.h:5172:5: note:   template argument deduction/substitution failed:
In file included from calc_shot.cpp:11:0:
descriptor.h:123:48: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘const char [2]’
       for (size_t k=1; k < d.size(); ++k) s << " " << d(k);
                                                ^

    mex: compile of ' "calc_shot.cpp"' failed.

我以前用 LD_PRELOAD 编译这段代码,但现在我不记得参数了,我该如何解决?

【问题讨论】:

  • 我注意到并非所有编译器都以相同的方式包含头文件。您可能必须包含一些额外的标题。例如,第一个 mesh.h:106:9: error: ‘sqrt’ is not a member of ‘std’。原因实际上可能是您需要#include &lt;cmath&gt;。可能还有其他类似的问题,但我不确定。
  • 另一个例子是descriptor.h:123:45: error: no match for ‘operator&lt;&lt;’ (operand types are ‘std::ostream {aka std::basic_ostream&lt;char&gt;}’ and ‘const char [2]’)。这个可能需要#include &lt;string&gt;
  • 代码很好,我曾经使用正确的参数编译它,但我不记得它们了
  • 好吧,显然代码中缺少标题。证据到处都是。我不知道您上次是如何将标头放入代码中的,但它们现在不存在。编译代码时可能会遗漏一些文件,或者可能还有其他内容。我建议您尝试更彻底地解释问题,并说明您为得到这些错误所做的工作。

标签: matlab mex ld-preload


【解决方案1】:

解决方案:

mex -v calc_shot.cpp shot_descriptor.cpp -DUSE_FLANN -I"C:\Program Files\flann\include" -I/usr/include/eigen3

使用此命令,程序就像魅力一样工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 2014-10-28
    • 1970-01-01
    • 2022-10-12
    相关资源
    最近更新 更多