如何通过 C++ 使用 Octave 库

发布于 2024-12-21 10:59:29 字数 1209 浏览 3 评论 0原文

这是我的第一个问题,如果它表述得不好或愚蠢的话,我很抱歉。

我正在尝试将八度音程库与 C++ 一起使用

我在 Ubuntu 上使用 Qt 创建者(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 文件中生成了此代码

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

该程序构建时没有错误。甚至不抱怨未定义的引用。但是当我运行它时,我

开始 /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

我不明白为什么它找不到该文件。我正在用肉眼看着文件。

我发现问题可能是权限问题,所以我将“liboctave.so.3.2.4”文件复制到项目位置,将其重命名为“liboctave.so”并为每个人添加了所有权限。然后使用 Qtcreator“添加库”功能添加此库,但我仍然遇到相同的错误。

请帮我

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

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

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();
}

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

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.

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.

Please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏天碎花小短裙 2024-12-28 10:59:29

liboctave 没有安装在标准位置,当你编译它时你的 povide
参数 -L$$PWD/../../../../usr/lib/octave-3.2.4/ 但是在运行中
时间尚不清楚。

所以你有两个选择:

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

    导出 LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4
    
  2. 使用可执行文件对路径进行硬编码使用附加选项:-Wl,-rpath=$$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.

So you have two options:

  1. Provide environment variable LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4 and then run the program:

    export LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4
    
  2. Hardcode the path withing excutable using an additional option: -Wl,-rpath=$$PWD/../../../../usr/lib/octave-3.2.4/

    And it would search for it in this location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文