在C ++文件中链接mat.h [英] Link mat.h in a C++ file

查看:134
本文介绍了在C ++文件中链接mat.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用mat.h在我的C ++代码中打开.mat文件.我的代码是:

I have to use mat.h for open a .mat file in my C++ code. My code is that:

#include "mat.h"
using namespace std;
int main() {
MATFile *pmat;
pmat = matOpen("ns3Da.mat","r");
return 0;
}

我用来编译的命令是:

g ++ program.cpp -I/usr/local/MATLAB/R2012a/extern/include -L/usr/local/MATLAB/R2012a/bin/* -L/usr/local/MATLAB/R2012a/extern/lib-o程序

g++ program.cpp -I/usr/local/MATLAB/R2012a/extern/include -L/usr/local/MATLAB/R2012a/bin/* -L/usr/local/MATLAB/R2012a/extern/lib -o program

我得到的错误是:

/tmp/ccSWqTnb.o:在函数"main"中:programma_c.cpp :(.text + 0x13):对'matOpen'的未定义引用collect2:错误:ld返回1退出状态

我使用Linux Ubuntu 16.04 LTS和Matlab 2012a版本.

I use Linux Ubuntu 16.04 LTS and Matlab 2012a version.

如何解决此错误?

推荐答案

编译中的 -L 标志指定搜索库的路径. -l <​​/code>标志应用于指定不带 lib 的库的名称,例如,在您的情况下,为 -lmat .因此,您的编译命令应类似于

The -L flag in compilation specifies the path to search for libraries. -l flag should be used to specify the name of library without lib, for instance, in your case -lmat. So your compilation command should be something like

g++ program.cpp -I/usr/local/MATLAB/R2012a/extern/include -L/usr/local/MATLAB/R2012a/bin/glnxa64 -L/usr/local/MATLAB/R2012a/extern/lib -lmat -o program

这篇关于在C ++文件中链接mat.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆