help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

.oct functions and shared libraries


From: John W. Eaton
Subject: .oct functions and shared libraries
Date: Tue, 8 Jun 1999 13:02:39 -0500 (CDT)

On  7-Jun-1999, Stef Pillaert <address@hidden> wrote:

| I have 2 .oct functions, created in .cc files (main.cc and sub.cc). They
| are both perfectly usable as stand-alone .oct functions, but in main.cc I
| call sub.cc. I do this by declaring (in main.cc) 
| octave_value_list Fsub (const octafve_value_list& args, int nargout);
| 
| Next I compile like this:
| 
| mkoctfile sub.cc
| rm sub.oct
| ar rc libtest.a sub.o
| 
| mkoctfile main.cc
| rm main.oct
| ar rc libtest.a main.o
| 
| mkoctfile sub.o -L. -ltest
| mkoctfile main.o -L. -ltest
| 
| All this works just fine. There should be cleaner ways to do this, but it
| is (to me ) an easy way to compile everything to .o files, and I put them
| all in the libtest.a library, so I can also use 'main.o' for later
| functions. In fact, I do this in a (very simple) Makefile, where I treat
| all .cc files the same way, and I don't have to worry too much about
| dependencies: when the libtest.a changes, I just relink all my functions
| against it, as in the last 2 lines above...)
| 
| **1: if someone has suggestions on this way of working, please do. I'm not
| very familiar with c++ and linking-libraries-compiling-...
| 
| **2: more important: can I do this with a shared library (libtest.so)? How
| do I do this? Just calling 'gcc -shared -o libtest.so main.o sub.o' instead
| of the 'ar'-calls, and leaving all the rest to what it is, results in
| errors while running the function in octave ("error in loading shared
| libraries: main.oct : undefined symbol : Fsub__FRC17octave_value_listi").
| However, 'nm libtest.so' shows me Fsub__FRC17octave_value_listi . Can
| someone point me in the right direction? Should there be something added to
| my source-code perhaps?
| 
| **3 Is there a way of creating a dynamic library with just the .oct-files
| themselves in it? So that I just need this library in my path, and not all
| the seperate .oct files? Or are just the .o files enough?
| How do I tell octave to look for functions in this library?

If you want to call a function defined in one .oct file from another,
I think the best way to do it is to use the feval function (declared
in toplev.h in the 2.0.x sources).  That does add a small amount of
overhead to the function call, but there are some advantages (such as,
it works).

A .oct file is just a shared library with some functions that follow a
naming and interface convention (details hidden and `enforced' by the
DEFUN macros).  You can create a single shared library with all your
functions in it and then use links in the filesystem to tell Octave
how to find all the functions:

  ln all_my_oct_functions.so foo.oct
  ln all_my_oct_functions.so bar.oct
  ln all_my_oct_functions.so baz.oct
  ...

If I remember correctly, linking a non-shared library into multiple
shared libraries (.oct files) can cause trouble on some systems if the
non-shared library has global or static data becuase it may happen
that you end up with two copies of the static or global data rather
than one.

jwe



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]