3
votes

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

1 Answers

2
votes

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.