How to use Octave libraries with C++

邮差的信 提交于 2019-12-10 18:05:38

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/8516356/how-to-use-octave-libraries-with-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!