comp.lang.ada
 help / color / mirror / Atom feed
* Help linking to Octave (mathematical) functions
@ 2014-12-19 21:31 Jerry
  2014-12-26 11:54 ` Blady
  0 siblings, 1 reply; 5+ messages in thread
From: Jerry @ 2014-12-19 21:31 UTC (permalink / raw)


Sorry for the long post.

I use GNAT on OS X 10.9.4. I'm trying to bind to a "loadable function" in Octave, specifically the modified Bessel function of the second kind which, using nm, appears to be in an .oct file at

/opt/local/lib/octave/3.6.4/oct/x86_64-apple-darwin13.3.0/besselj.oct

and not having any luck. (Several kinds of Bessel functions seem to be stored in besselj.oct.)

.oct files are described here

http://octave.sourceforge.net/coda/c58.html

and are said to be shared libraries or shared objects.

I have successfully bound to other Octave functions which are called "built-in" and are found on my machine at 

/opt/local/lib/octave/3.6.4/liboctave.dylib

The gpr library file that I use for the "built-in" functions and that works is this:

library project Octave_Library is
    for Externally_Built use "true";
    for Library_Dir use "/opt/local/lib/octave/3.6.4/";
    for Library_Name use "octave";
    for Library_Kind use "dynamic";
end Octave_Library;

I don't know why the Octave folks divide things up like this ("built-in" and "loadable") but I'm sure there's a good reason. I also dont't know what the structure of .oct files is but nm seemed to not choke so maybe they are like other library files. In any event, I have tried the following library description (in its own file):

library project Octave_oct_Library is
    for Externally_Built use "true";
    for Library_Dir use "/opt/local/lib/octave/3.6.4/oct/x86_64-apple-darwin13.3.0";
    for Library_Name use "besselj";
    for Library_Kind use "dynamic";
end Octave_oct_Library;

My main gpr file contains these two lines:

with "Octave_Library"; -- Octave built-in functions (not the loadable functions from Octave)
with "Octave_oct_Library"; -- Octave loadable functions. First try with Bessel functions only.

When I build this complaint results:

ld: library not found for -lbesselj

Note the "l" in front of besselj

I tried making a symlink to the besselj.oct file and tried to trick the linker by changing its name in a few ways with no success. However, when I named the symlink libbesselj.dylib I got this result:

ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file '/opt/local/lib/octave/3.6.4/oct/x86_64-apple-darwin13.3.0//libbesselj.dylib' for architecture x86_64

which seems to indicate that the .oct file is something called a MH_BUNDLE. (And why the "//" in the error message?) I found this discussion about MH_BUNDLE

http://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-osx

which prompted me to do this:

$ otool -hv besselj.oct
besselj.oct:
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  X86_64        ALL  0x00      BUNDLE    21       2128   NOUNDEFS DYLDLINK TWOLEVEL WEAK_DEFINES BINDS_TO_WEAK

At this point I'm in way over my head.

I use Ada nearly daily for general technical computing and supplement with Octave, Mathematica, and Igor Pro. Having a full binding to the Octave libraries (as well as GSL for example) would vastly help me and other Ada users but for now I'm just adding single-function bindings as I need them.

Thanks for any help.

Jerry


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help linking to Octave (mathematical) functions
  2014-12-19 21:31 Help linking to Octave (mathematical) functions Jerry
@ 2014-12-26 11:54 ` Blady
  2014-12-28  3:38   ` Jerry
  0 siblings, 1 reply; 5+ messages in thread
From: Blady @ 2014-12-26 11:54 UTC (permalink / raw)


Hello Jerry,

Despite the documentation said it is like "shared library or shared 
object", it is referring to Octave itself "An oct-file is a dynamical 
extension of the Octave interpreter".
On MacOS, even with GNAT, at the end, all object files are loaded by ld 
but I haven't seen that oct files are supported by ld.

In the documentation it is specified at §1.1.3.5. Running: "If the 
oct-file is in the LOADPATH, it will be loaded automatically – either 
when requesting help on the function or when invoking it directly."

Have you set LOADPATH to your bessel library?

HTH, Pascal.

Le 19/12/2014 22:31, Jerry a écrit :
> Sorry for the long post.
>
> I use GNAT on OS X 10.9.4. I'm trying to bind to a "loadable function" in Octave, specifically the modified Bessel function of the second kind which, using nm, appears to be in an .oct file at
>
> /opt/local/lib/octave/3.6.4/oct/x86_64-apple-darwin13.3.0/besselj.oct
>
> and not having any luck. (Several kinds of Bessel functions seem to be stored in besselj.oct.)
>
> .oct files are described here
>
> http://octave.sourceforge.net/coda/c58.html
>
> and are said to be shared libraries or shared objects.
>
> I have successfully bound to other Octave functions which are called "built-in" and are found on my machine at
>
> /opt/local/lib/octave/3.6.4/liboctave.dylib
>
> The gpr library file that I use for the "built-in" functions and that works is this:
>
> library project Octave_Library is
>      for Externally_Built use "true";
>      for Library_Dir use "/opt/local/lib/octave/3.6.4/";
>      for Library_Name use "octave";
>      for Library_Kind use "dynamic";
> end Octave_Library;
>
> I don't know why the Octave folks divide things up like this ("built-in" and "loadable") but I'm sure there's a good reason. I also dont't know what the structure of .oct files is but nm seemed to not choke so maybe they are like other library files. In any event, I have tried the following library description (in its own file):
>
> library project Octave_oct_Library is
>      for Externally_Built use "true";
>      for Library_Dir use "/opt/local/lib/octave/3.6.4/oct/x86_64-apple-darwin13.3.0";
>      for Library_Name use "besselj";
>      for Library_Kind use "dynamic";
> end Octave_oct_Library;
>
> My main gpr file contains these two lines:
>
> with "Octave_Library"; -- Octave built-in functions (not the loadable functions from Octave)
> with "Octave_oct_Library"; -- Octave loadable functions. First try with Bessel functions only.
>
> When I build this complaint results:
>
> ld: library not found for -lbesselj
>
> Note the "l" in front of besselj
>
> I tried making a symlink to the besselj.oct file and tried to trick the linker by changing its name in a few ways with no success. However, when I named the symlink libbesselj.dylib I got this result:
>
> ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file '/opt/local/lib/octave/3.6.4/oct/x86_64-apple-darwin13.3.0//libbesselj.dylib' for architecture x86_64
>
> which seems to indicate that the .oct file is something called a MH_BUNDLE. (And why the "//" in the error message?) I found this discussion about MH_BUNDLE
>
> http://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-osx
>
> which prompted me to do this:
>
> $ otool -hv besselj.oct
> besselj.oct:
> Mach header
>        magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
> MH_MAGIC_64  X86_64        ALL  0x00      BUNDLE    21       2128   NOUNDEFS DYLDLINK TWOLEVEL WEAK_DEFINES BINDS_TO_WEAK
>
> At this point I'm in way over my head.
>
> I use Ada nearly daily for general technical computing and supplement with Octave, Mathematica, and Igor Pro. Having a full binding to the Octave libraries (as well as GSL for example) would vastly help me and other Ada users but for now I'm just adding single-function bindings as I need them.
>
> Thanks for any help.
>
> Jerry
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help linking to Octave (mathematical) functions
  2014-12-26 11:54 ` Blady
@ 2014-12-28  3:38   ` Jerry
  2014-12-29  9:21     ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Jerry @ 2014-12-28  3:38 UTC (permalink / raw)


On Friday, December 26, 2014 4:54:55 AM UTC-7, Blady wrote:

Thanks, Pascal.

> Hello Jerry,
> 
> Despite the documentation said it is like "shared library or shared 
> object", it is referring to Octave itself "An oct-file is a dynamical 
> extension of the Octave interpreter".
> On MacOS, even with GNAT, at the end, all object files are loaded by ld 
> but I haven't seen that oct files are supported by ld.

That's not good. I wonder if the internal structure of an oct file is similar to other files known by ld. I suppose this is a question for the Octave developer list.
> 
> In the documentation it is specified at §1.1.3.5. Running: "If the 
> oct-file is in the LOADPATH, it will be loaded automatically - either 
> when requesting help on the function or when invoking it directly."
> 
> Have you set LOADPATH to your bessel library?

Your comment seems to apply to using Octave itself to find the oct file so that Octave can load the file when it needs it. (To answer your question, No, I haven't, but I suppose the Octave installer did since Octave finds these files.) I'm trying to link the oct file to an Ada program. Is not LOADPATH an Octave-only concept?

Jerry
> 
> HTH, Pascal.
> 
> Le 19/12/2014 22:31, Jerry a écrit :

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help linking to Octave (mathematical) functions
  2014-12-28  3:38   ` Jerry
@ 2014-12-29  9:21     ` Stephen Leake
  2014-12-30  3:24       ` Jerry
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2014-12-29  9:21 UTC (permalink / raw)


Jerry <lanceboyle@qwest.net> writes:

>> Despite the documentation said it is like "shared library or shared 
>> object", it is referring to Octave itself "An oct-file is a dynamical 
>> extension of the Octave interpreter".
>> On MacOS, even with GNAT, at the end, all object files are loaded by ld 
>> but I haven't seen that oct files are supported by ld.
>
> That's not good. I wonder if the internal structure of an oct file is
> similar to other files known by ld. I suppose this is a question for
> the Octave developer list.

Yes. Or a Mac list; the problem seems to be with the "bundle" stuff.

Can you try this on a Linux distribution?


Since this is all open source, you could try compiling the bessel
library from source using GNAT, and either creating a more standard
library or just include it in your main project.


Another option is to link the Octave interpreter to the Ada program, and
then tell it to load the oct-file.

There may be an Octave library that lets you do this, hopefully with an
Ada binding available.

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help linking to Octave (mathematical) functions
  2014-12-29  9:21     ` Stephen Leake
@ 2014-12-30  3:24       ` Jerry
  0 siblings, 0 replies; 5+ messages in thread
From: Jerry @ 2014-12-30  3:24 UTC (permalink / raw)


On Monday, December 29, 2014 2:21:09 AM UTC-7, Stephen Leake wrote:
> Jerry writes:
> 
> >> Despite the documentation said it is like "shared library or shared 
> >> object", it is referring to Octave itself "An oct-file is a dynamical 
> >> extension of the Octave interpreter".
> >> On MacOS, even with GNAT, at the end, all object files are loaded by ld 
> >> but I haven't seen that oct files are supported by ld.
> >
> > That's not good. I wonder if the internal structure of an oct file is
> > similar to other files known by ld. I suppose this is a question for
> > the Octave developer list.
> 
> Yes. Or a Mac list; the problem seems to be with the "bundle" stuff.

Yes. I hope to get back to this soon, one way or another.
> 
> Can you try this on a Linux distribution?

Not easily. I don't have Linux installed on my Mac. But I see what you're getting at--the bundle stuff might be a Mac anomaly; I've seen MH_BUNDLE discussed on other lists but mostly it goes over my head.
> 
> 
> Since this is all open source, you could try compiling the bessel
> library from source using GNAT, and either creating a more standard
> library or just include it in your main project.

I hadn't thought of that. Seems reasonable and obvious now that you mention it. OTOH the Numerical Recipes book has a very quick solution based on Abramowitz & Stegun.
> 
> 
> Another option is to link the Octave interpreter to the Ada program, and
> then tell it to load the oct-file.
> 
> There may be an Octave library that lets you do this, hopefully with an
> Ada binding available.

Not sure how that would proceed. But for an earlier case where I needed a bit of Octave in an Ada program I did a hilariously crude thing: I had the Ada program write out the Octave source script to a text file then called Octave with pragma Import(C, system) (not sure why I didn't use GNAT.OS_Lib.Spawn), had Octave write out the answer to a new text file, and read that text file with the Ada program. A tad slow I would surmise but I then needed only one call to Octave.

Jerry
> 
> -- 
> -- Stephe

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-12-30  3:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19 21:31 Help linking to Octave (mathematical) functions Jerry
2014-12-26 11:54 ` Blady
2014-12-28  3:38   ` Jerry
2014-12-29  9:21     ` Stephen Leake
2014-12-30  3:24       ` Jerry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox