help-octave
[Top][All Lists]
Advanced

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

Re: Linking C++ classes in non-octave applications [liboctave]


From: Douglas Eck
Subject: Re: Linking C++ classes in non-octave applications [liboctave]
Date: Tue, 19 Feb 2002 09:45:15 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011221

Hi Jan,

This is not so hard to do. The challenge is in making sure you link
to the appropriate libs when you compile your application. As of
octave-2.1.35 you need to link to quite a few libs. However, John Eaton
said in a posting some time back that this will be simplified
quite a bit in 2.1.36. Once you can compile a simple liboctave app,
you are free to link to other libraries. I for example have linked
a liboctave-linked app to some MIDI libs that are themselves linked dynamically
against libqt. And everything worked out.

Let me say that it's a quite nice environment to work in. You have access to
all of the octave data structures. Also, you have the ability to call your 
program
from the octave interpreter, making it easy to pass in and write out
data to disk via .mat files. And with a standalone app you can use
easily use gdb and gprof!

I included a Makefile and helloWorld.cc which compiles on
my debian box. Your mileage may vary depending on how octave
was compiled. Also, if you're using windows, then please
let me know if you have success. I haven't been able to get
a standalone app to compile on windows (cygwin).

Finally, a special note on kpathsea. As of now, octave uses a modified kpathsea.
This means that you must have the libkpathsea from the octave sources!
You'll see in my Makefile that I add /usr/src/octave-2.1.35/kpathsea
to the library path. Hopefully upstream changes will be made to kpathsea
so that this is no longer necessary... but I'm not clear on the status
of this right now.

Cheers,
Doug



Jan D'hooge wrote:

Hi,

I'm new to the octave source code but I thought of using (part of) it as
a basic vector/matrix/arrays C++ library. I compiled the Octave
libraries without too much problem but linking them with my own
applications doesn't seem soo straight forward.

Has anyone ever tried to create this kind of library from the Octave
classes? Wouldn't it a good idea to do so? There aren't any good, free
algebra libraries available from the net to my knowledge. Of course, I
wouldn't mind doing this (as I need them myself) but some additional
documentation on the C++ classes would be practical. Is more available
on the structure of the classes and how they inter-relate?


Thanks,

Jan.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------





--
Dr. Douglas Eck, http://www.idsia.ch/~doug
Istituto Dalle Molle di Studi sull'Intelligenza Artificiale (IDSIA)
Neural Networks, Rhythm Perception and Production, Dynamical Systems
//Douglas Eck address@hidden


#include <octave/oct.h>

int main(void) {  
  int sz=20;
  Matrix m = Matrix(sz,sz);
  for (int r=0;r<sz;r++) {
    for (int c=0;c<sz;c++) {
      m(r,c)=r*c;
    }
  }
  cout << "Hello world! " << endl;
  cout << m;
}






 
##A simple makefile for linking against octave 2.1.35 liboctave

OPTIMIZATION = -pg -g
OCTAVE_VERSION=2.1.35
CC=c++ 
CCINCLUDES=-I/usr/include/octave-$(OCTAVE_VERSION) 
-I/usr/include/octave-$(OCTAVE_VERSION)/octave 
CCFLAGS=-mieee-fp -fno-rtti -fno-exceptions -fno-implicit-templates  
$(OPTIMIZATION)
LD_LIBS=-lblas -loctave -loctinterp -ldl  -lcruft  -lg2c -ltermcap -lhdf5 
-lreadline -lkpathsea -lfftw 
LD_PATHS=-L/usr/lib/octave-$(OCTAVE_VERSION) 
-L/usr/src/octave-$(OCTAVE_VERSION)/kpathsea  

helloWorld: helloWorld.o
        g++ $(OPTIMIZATION) helloWorld.o -o helloWorld $(LD_PATHS) $(LD_LIBS)

helloWorld.o: helloWorld.cc
        g++ -c $(OPTIMIZATION) helloWorld.cc -o helloWorld.o $(CCINCLUDES) 

clean:
        rm helloWorld.o helloWorld







reply via email to

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