如何在C ++中使用Octave库 [英] How to use Octave libraries with C++

查看:909
本文介绍了如何在C ++中使用Octave库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里的第一个问题,如果措辞不当或愚蠢,请对不起.

This is my first question here, so sorry in forward if it is not well formulated or stupid.

我正在尝试将octave库与C ++一起使用

I am trying to use the octave libraries with C++

我正在Ubuntu(linux noob)上使用Qt Creator

I am using Qt creator on Ubuntu (linux noob)

#include "octave/oct.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Matrix matrix(3,4);

    return a.exec();
}

起初,我遇到了一些未定义的引用错误.我发现程序缺少库,因此我寻找了库"liboctave.so".我在usr/lib/octave-3.2.4中找到了它.更精确地说,有一个名为"liboctave.so"的符号链接指向"liboctave.so.3.2.4"文件.我使用QtCreators的添加库"功能将库添加到我的项目中.该程序在我的.pro文件中生成了此代码

At first I got some undefined references errors. I figured out the program is missing libraries, so I looked for the library "liboctave.so". I found it in usr/lib/octave-3.2.4. To be more precise there was a symbolic link named "liboctave.so" pointing to "liboctave.so.3.2.4" file. I used the QtCreators "add Library" feature to add the library to my project. The program generated this code in my .pro file

unix:!macx:!symbian: LIBS += -L$$PWD/../../../../usr/lib/octave-3.2.4/ -loctave

INCLUDEPATH += $$PWD/../../../../usr/lib/octave-3.2.4
DEPENDPATH += $$PWD/../../../../usr/lib/octave-3.2.4

程序无错误构建.甚至不抱怨未定义的引用.但是当我运行它时,我会得到

The program built without error. Not even complaining about undefined references. But when I run it I get

开始/home/martin/Projects/test-build-desktop/test ...

Starting /home/martin/Projects/test-build-desktop/test...

/home/martin/Projects/test-build-desktop/test: error while loading shared libraries: liboctave.so: cannot open shared object file: No such file or directory
/home/martin/Projects/test-build-desktop/test exited with code 127

我不知道为什么找不到文件.我用裸眼看着文件.

I cannot figure out why it cannot find the file. I am looking at the file with my bare eyes.

我发现问题可能出在权限上,所以我将"liboctave.so.3.2.4"文件复制到项目位置,将其重命名为"liboctave.so",并为所有人添加了所有权限.然后使用Qtcreator的添加库"功能添加了该库,但仍然出现相同的错误.

I figured out that the problem may be permission, so I copied the "liboctave.so.3.2.4" file to the project location, renamed it "liboctave.so" and added all permissions for everybody. Then added this library using the Qtcreator "add library" feature and I still get the same error.

请帮助我

推荐答案

在编译povide时,liboctave未安装在标准位置 参数-L$$PWD/../../../../usr/lib/octave-3.2.4/,但是在运行中 时间未知.

The liboctave is not installed in standard location, when you compile it your povide a parameter -L$$PWD/../../../../usr/lib/octave-3.2.4/ however in the run time it is not known.

因此,您有两个选择:

  1. 提供环境变量LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4,然后运行程序:

export LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4

  • 使用其他选项对路径进行可执行的硬编码:-Wl,-rpath=$$PWD/../../../../usr/lib/octave-3.2.4/

    它将在此位置搜索它.

    这篇关于如何在C ++中使用Octave库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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