C ++保存mat文件,构建日志显示"undefined reference to 'H5Tget_member_type'....................."



当我使用 CodeBlock 编译一个 c++ 程序以将矩阵保存到 mat 文件中时,以下是在 Linux 上的构建日志。我已经设置了构建选项、链接器设置、链接库、libmat.so、libeng.so libmx.so。在搜索目录中,在选项卡编译器中,我添加"/usr/local/MATLAB/R2011a/extern/include",在选项卡链接器中,我添加"/usr/local/MATLAB/R2011a/bin/glnx86"。构建日志是什么意思?如何解决?

源代码:

#include <string>
#include <iostream>
#include "matrix.h"
#include "mat.h"
using namespace std;
void saveMat(mxArray* m, const string fileName){
MATFile* pmatFile = NULL;
mxArray* pMxArray = NULL;
string whole_name = fileName + ".mat";
pmatFile = matOpen(whole_name.c_str(),"w");
int row_num = mxGetM(m);
int col_num = mxGetN(m);
pMxArray = mxCreateDoubleMatrix(row_num, col_num, mxREAL);
double *data;
data = mxGetPr(m);
mxSetData(pMxArray, data);
unsigned found = fileName.find_last_of("/\");
string name = fileName.substr(found+1);
matPutVariable(pmatFile, name.c_str(),pMxArray);
matClose(pmatFile);}

构建日志:

warning: libmwfl.so, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmat.so, not found (try using -rpath or -rpath-link)
warning: libut.so, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmat.so, not found (try using -rpath or -rpath-link)
warning: libmx.so, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmat.so, not found (try using -rpath or -rpath-link)
warning: libhdf5_hl.so.6, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmat.so, not found (try using -rpath or -rpath-link)
warning: libhdf5.so.6, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmat.so, not found (try using -rpath or -rpath-link)
warning: libmwresource_core.so, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libmwi18n.so, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libmwMATLAB_res.so, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libboost_date_time.so.1.40.0, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libboost_system.so.1.40.0, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libboost_thread.so.1.40.0, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libicudata.so.42, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libicuuc.so.42, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libicui18n.so.42, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
warning: libicuio.so.42, needed by /usr/local/MATLAB/R2011a/bin/glnx86/libmx.so, not found (try using -rpath or -rpath-link)
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Tget_member_type'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `ut_array_length'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5P_CLS_FILE_CREATE_g'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5T_NATIVE_SHORT_g'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `resource_core::BaseMsgID::getName() const'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Pset_type_conv_cb'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Pcreate'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Tcopy'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `ut_ghash_query'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Aget_space'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Sget_simple_extent_dims'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MATLAB::checkDimCommon::nonnegativeSize::nonnegativeSize()'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `utInferInstallRoot()'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MATLAB::checkDimCommon::complexSize::complexSize()'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Eset_auto2'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `utSingleConvert'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `utf16_strlen_lim'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `utGetFormatEndian'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `utf16_strcpy'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Sget_simple_extent_ndims'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Aget_type'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Fcreate'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MATLAB::colon::logicalInput::logicalInput()'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Sset_extent_simple'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Pset_layout'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Sclose'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `utFinite'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `utF2cstr'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Rcreate'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `utFlipFourBytes'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5T_NATIVE_SCHAR_g'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Scopy'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MATLAB::Cell2Struct::InvalidFieldName::InvalidFieldName(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Tlock'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Tget_class'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `typeinfo for MathWorks::System::InternalException'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `fl::mem::aligned_heap::instance'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `utLogWarning(utWarningManagerContext*, char const*, char const*, char*, char const*, bool)'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Gunlink'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Tget_nmembers'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `utFree'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `ucnv_reset_4_2'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MATLAB::getReshapeDims::notSameNumel::notSameNumel()'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Acreate2'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MathWorks::I18N::cast(MathWorks::I18N::UnicodeConverterX*)'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `utTmpnam'
/usr/local/MATLAB/R2011a/bin/glnx86/libmx.so||undefined reference to `MATLAB::AddField::InvalidFieldName::InvalidFieldName(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Aclose'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5T_NATIVE_ULONG_g'
/usr/local/MATLAB/R2011a/bin/glnx86/libmat.so||undefined reference to `H5Pset_deflate'
More errors follow but not being shown.
Edit the max errors limit in compiler options...
=== Build finished: 50 errors, 15 warnings ===

我遇到了同样的问题。

这是因为 libmat 和 libmx 调用同一文件夹中的其他库文件。尝试使用 的链接器选项嵌入路径

-

wl,-rpath=LIBRARY_PATH

具体来说,在我的计算机上,我使用以下命令进行编译,它可以工作

g++ -I/usr/local/MATLAB/R2013a/extern/include -L/usr/local/MATLAB/R2013a/bin/glnxa64

sourcefile.cpp -o target -lmat -lmx -wl,-rpath=/usr/local/MATLAB/R2013a/bin/glnxa64

我认为您应该将"matlabroot/bin/glnxa64"添加到您的LD_LIBRARY_PATH中,其中"matlabroot"是指MATLAB安装的根文件夹。因此,链接器可以自动找到所需的库,而无需添加太多特定的库依赖项。

相关内容

  • 没有找到相关文章

最新更新