Mattia
Mattia

Reputation: 21

Mex files on Mountain Lion: explicit instantiation error

I'm working with MATLAB r2012b on Mountain Lion, and XCode version installed is 4.6.1. I've also used the patch at http://www.mathworks.it/support/solutions/en/data/1-IXBVKD/ and then I have typed "mex - setup" and selected the only option available

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

I'm trying to use a framework for sparse modeling (written in C++) which uses mex files. In order to install the previous framework I have to call a matlab file inside the framework which calls mex function: however when I call this function I get the following message...

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.

The problem is not connected to the framework. Googling I have seen that I'm not the only one with this problem with matlab, but I don't know how to fix it. Thank you very much in advance for any help.

Mattia

UPDATE:

I've discovered that the error is produced by the following blocks of code

Block 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;
        }
     }
};

Block 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 ");
};

Block 3

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

And block 4

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

and the error is always due to the first line of the above blocks, that is ...

cerr << name << endl;

Commenting the above line in the 4 blocks the compiling terminates successfully.

Does somebody know why this happens?

Upvotes: 2

Views: 884

Answers (2)

user2428646
user2428646

Reputation: 11

I solved a similar problem by changing the MACOSX_DEPLOYMENT_TARGET='10.5' to '10.6' in mexopts.sh.

Upvotes: 1

Sam Anthony
Sam Anthony

Reputation: 21

I solved this problem by adding the compile flag "-mmacosx-version-min=10.7" via the line

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

in the SPAMS framework's compile.m immediately before the for block that calls mex.

This solution came from Trying to build muParser: error: explicit instantiation of 'std::basic_ostream but no definition available and Building libsigc++ fails (std::basic_ostream explicit instantiation) which appear to be the same problem with other packages.

Upvotes: 2

Related Questions