Mountain Lion上的Mex文件:显式实例化错误 [英] Mex files on Mountain Lion: explicit instantiation error
问题描述
我正在Mountain Lion上使用MATLAB r2012b,安装的XCode版本是4.6.1.我还在 http://www.mathworks处使用了该修补程序. /support/solutions/en/data/1-IXBVKD/,然后键入"mex-setup"并选择唯一可用的选项
1: /Applications/MATLAB_R2012b.app/bin/mexopts.sh : Template Options file for building gcc MEX-files
我正在尝试使用一个稀疏建模框架(用C ++编写),该框架使用mex文件.为了安装以前的框架,我必须在调用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个块中注释以上行,编译成功终止.
有人知道为什么会这样吗?
我通过在行中添加编译标志"-mmacosx-version-min = 10.7"解决了这个问题
compile_flags=[compile_flags ' -mmacosx-version-min=10.7'];
紧接在调用mex的for块之前的SPAMS框架的compile.m中.
此解决方案来自尝试构建muParser:错误:'std :: basic_ostream的显式实例化,但没有可用的定义和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?
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.
这篇关于Mountain Lion上的Mex文件:显式实例化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!