2

我在 Mountain Lion 上使用 MATLAB r2012b,安装的 XCode 版本是 4.6.1。我还使用了http://www.mathworks.it/support/solutions/en/data/1-IXBVKD/上的补丁,然后我输入了“mex - setup”并选择了唯一可用的选项

1: /Applications/MATLAB_R2012b.app/bin/mexopts.sh : Template Options file for building gcc MEX-files

我正在尝试使用一个使用 mex 文件的稀疏建模框架(用 C++ 编写)。为了安装以前的框架,我必须在框架内调用一个调用 mex 函数的 matlab 文件:但是当我调用这个函数时,我收到以下消息......

compilation of: -I./linalg/ -I./decomp/ -I./dictLearn/ dictLearn/mex/mexTrainDL.cpp
./linalg/linalg.h: In member function 'void Matrix<T>::print(const std::string&) const [with T = float]':
./linalg/linalg.h:1084:   instantiated from 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
./linalg/linalg.h:1084:   instantiated from 'void Matrix<T>::print(const std::string&) const [with T = float]'
dictLearn/mex/mexTrainDL.cpp:197:   instantiated from here
./linalg/linalg.h:1084: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
./linalg/linalg.h: At global scope:
./linalg/linalg.h: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
./linalg/linalg.h:1084:   instantiated from 'void Matrix<T>::print(const std::string&) const [with T = float]'
dictLearn/mex/mexTrainDL.cpp:197:   instantiated from here
./linalg/linalg.h:1084: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
./linalg/linalg.h: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
./linalg/linalg.h:1084:   instantiated from 'void Matrix<T>::print(const std::string&) const [with T = float]'
dictLearn/mex/mexTrainDL.cpp:197:   instantiated from here
./linalg/linalg.h:1084: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available

mex: compile of ' "dictLearn/mex/mexTrainDL.cpp"' failed.

问题与框架无关。谷歌搜索我发现我不是唯一一个遇到 matlab 问题的人,但我不知道如何解决它。非常感谢您的任何帮助。

马蒂亚

更新:

我发现错误是由以下代码块产生的

区块 1:

/// print the sparse matrix
template<typename T> inline void SpMatrix<T>::print(const string& name) const {
    cerr << name << endl;
    cerr << _m << " x " << _n << " , " << _nzmax << endl;
    for (int i = 0; i<_n; ++i) {
        for (int j = _pB[i]; j<_pE[i]; ++j) {
            cerr << "(" <<_r[j] << "," << i << ") = " << _v[j] << endl;
        }
     }
};

第 2 座

/// Print the matrix to std::cout
template <typename T> inline void Matrix<T>::print(const string& name) const {
   std::cerr << name << std::endl;
   std::cerr << _m << " x " << _n << std::endl;
   for (int i = 0; i<_m; ++i) {
      for (int j = 0; j<_n; ++j) {
         printf("%10.5g ",static_cast<double>(_X[j*_m+i]));
         //         std::cerr << _X[j*_m+i] << " ";
      }
      printf("\n ");
      //std::cerr << std::endl;
   }
   printf("\n ");
};

区块 3

template <typename T> void ShiftMatrix<T>::print(const string& name) const {
   cerr << name << endl;
   cerr << "Shift Matrix: " << _shifts << " shifts" << endl;
   _inputmatrix->print(name);
};

和第 4 块

template <typename T> void DoubleRowMatrix<T>::print(const string& name) const {
   cerr << name << endl;
   cerr << "Double Row Matrix" << endl;
   _inputmatrix->print(name);
};

并且错误总是由于上述块的第一行,即...

cerr << name << endl;

在 4 个块中注释上述行,编译成功终止。

有人知道为什么会这样吗?

4

2 回答 2

2

我通过该行添加编译标志“-mmacosx-version-min=10.7”解决了这个问题

compile_flags=[compile_flags ' -mmacosx-version-min=10.7'];

在 SPAMS 框架的 compile.m 中,紧接在调用 mex 的 for 块之前。

这个解决方案来自Trying to build muParser: error: explicit instantiation of 'std::basic_ostream but no definition available and Building libsigc++ failed (std::basic_ostream explicit instantiation)这似乎与其他包相同的问题。

于 2013-04-24T21:41:19.863 回答
1

我通过在 mexopts.sh 中将 MACOSX_DEPLOYMENT_TARGET='10.5' 更改为 '10.6' 解决了类似的问题。

于 2013-05-28T13:12:11.800 回答