help-octave
[Top][All Lists]
Advanced

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

Re: call c++ dlls in octave


From: Tatsuro MATSUOKA
Subject: Re: call c++ dlls in octave
Date: Fri, 19 Dec 2008 09:23:31 +0900 (JST)

Hello Allahyari Rahim

Fist you should read the octave manual carefully: 

Appendix A Dynamically Linked Functions

in the octave.pdf in the documentation, which can be accessed from start menu 
of octave.

Sometimes you have to read liboctave.pdf (Octave C++ Classes)

(This is hard to read with out knowledge of C++.)

If you want to write oct file, you should read A.1 Oct-Files.
You can build .oct file using mkoctfile.

If you want to build a stand alone program, you can build .exe file using 
mkoctfile
--link-stant-alone. At the end of this mail I have shown  an example of stand 
alone program. 


Regards

Tatsuro

/*ใ€€test.cc example stand alone program
Octave 
solving ODE by LSODE
*/

#include <iostream>
#include <octave/oct.h>
#include <octave/LSODE.h> 

using namespace std;

ColumnVector test(const ColumnVector& y, double t){
        ColumnVector dy(2);
        dy(0)=y(0)+2*y(1);
        dy(1)=-4*y(0)-3*y(1);
        return dy;
}

int main()
{
        ColumnVector yi(2), t(41);
        Matrix dat_m(41,3);
        ODEFunc odef(test);
        int i;
        yi(0)=0.0;
        yi(1)=1.0;
        LSODE ls(yi,0.0,odef);
        for(i=0;i<=40;i++) t(i)=0.1*i;
        dat_m.insert(t,0,0);
        Matrix y=ls.do_integrate(t);
        dat_m.insert(y,0,1);
        cout << "# Matrix dat_m" << endl <<  dat_m << endl;

}
// end


octave.exe:2:C:\Programs\Octave\3.0.2_gcc-4.3.0\bin
> cd D:\usr\Tatsu\program\Octave\test2
octave.exe:3:~\program\Octave\test2
> mkoctfile --link-stand-alone -s -o test.exe test.cc
Info: resolving vtable for LSODE by linking to __imp___ZTV5LSODE (auto-import)
c:/programs/octave/3.0.2_gcc-4.3.0/mingw32/bin/../lib/gcc/mingw32/4.3.0-dw2/../../../../mingw32/bin/ld.exe:
warning: aut
o-importing has been activated without --enable-auto-import specified on the 
command line.
This should work unless it involves constant data structures referencing 
symbols from auto-imported
DLLs.strip:test.cc:
File format not recognized
octave.exe:4:~\program\Octave\test2
> system('cmd')
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\usr\Tatsu\program\Octave\test2>dir test.exe
 Volume in drive D has no label.
 Volume Serial Number is ACCF-78A8

 Directory of D:\usr\Tatsu\program\Octave\test2

2008/12/19  09:11            77,896 test.exe
               1 File(s)         77,896 bytes
               0 Dir(s)  36,908,322,816 bytes free

D:\usr\Tatsu\program\Octave\test2>test
# Matrix dat_m
 0 0 1
 0.1 0.179763 0.707037
 0.2 0.318829 0.435272
 0.3 0.418297 0.193126
 0.4 0.480858 -0.0138417
 0.5 0.510378 -0.182668
 0.6 0.511514 -0.312648
 0.7 0.48936 -0.404957
 0.8 0.449138 -0.462258
 0.9 0.395937 -0.48831
 1 0.334512 -0.487604
 1.1 0.269125 -0.46502
 1.2 0.203446 -0.425545
 1.3 0.140491 -0.37402
 1.4 0.0826072 -0.314957
 1.5 0.0314883 -0.252386
 1.6 -0.0117854 -0.189767
 1.7 -0.0466831 -0.129935
 1.8 -0.0731481 -0.0750853
 1.9 -0.0915148 -0.0267894
 2 -0.102422 0.0139609
 2.1 -0.10673 0.0466944
 2.2 -0.105441 0.071387
 2.3 -0.0996265 0.0883821
 2.4 -0.0903702 0.0983078
 2.5 -0.0787135 0.101998
 2.6 -0.0656175 0.100416
 2.7 -0.0519342 0.0945891
 2.8 -0.0383875 0.0855498
 2.9 -0.0255641 0.0742883
 3 -0.0139114 0.0617156
 3.1 -0.0037432 0.0486368
 3.2 0.00475074 0.0357338
 3.3 0.0114906 0.0235571
 3.4 0.0164902 0.0125246
 3.5 0.0198393 0.00292671
 3.6 0.021686 -0.00506346
 3.7 0.0222193 -0.0113767
 3.8 0.0216532 -0.0160322
 3.9 0.0202125 -0.0191203
 4 0.0181209 -0.0207857



--- Tatsuro MATSUOKA <address@hidden> wrote:

> --- address@hidden wrote:
> 
> > Date:Thu, 18 Dec 2008 21:54:30 +0900 (JST)
> > From:address@hidden
> > Subject:Re: call c++ dlls in octave
> > To:address@hidden
> > 
> > Oh you are using theoctave-mingw!  My instruction is for octave-msvc.  
> > 
> > Your problem is more general so that I cannot answer at the moment. 
> > 
> > --------------------------------------
> > Power up the Internet with Yahoo! Toolbar.
> > http://pr.mail.yahoo.co.jp/toolbar/
> > 
> --- Allahyari Rahim <address@hidden> wrote:
> 
> > Hi,
> > &#65533;
> > I have to call a lot of function from a folder for example TWUClib
> > In this folder are my head and source files. Is it possible to call all 
> > this directly from
> > octave or I have to copy all into octave listing? 
> > &#65533;&#65533;
> > What can I do with \x9C#include <octave/oct.h>\x9D 
> > and function&#65533; DEFUN_DLD (oregonator, args, ,&#65533; "The 
> > `oregonator'.")
> > do I need to include all my function with #include <octave/oct.h>
> > or can I build a file for example myfile.cc and and call all function from 
> > this file&#65533;//
> > myfile.cc#include&#65533; <octave/oct.h> #include <TWUClib.h>DEFUN_DLD 
> > (oregonator, args,
> ,&#65533;
> "The
> > `oregonator'."){&#65533;&#65533;&#65533; ็šƒ.&#65533;&#65533;&#65533; 
> > TWUopenSignal2(char const
> * a,
> char const * b, char const * c,
> > int d );&#65533;&#65533;&#65533;
> ็šƒ.&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
>  }
> > &#65533;I apropos &#65533;tested &#65533;&#65533;oregonator file. 
> > &#65533;it is running.
> Without any
> problem.
> > &#65533;
> > &#65533;
> >
>
&#65533;[.]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> hello.oct&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> [MSYS]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> [share]
> >
>
[..]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> [include]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> octave-core&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; testOrego2.m
> >
>
[bin]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
>
[lib]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> oregonator.cc&#65533;&#65533;&#65533;&#65533; [tools]
> >
>
[doc]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> [libexec]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> oregonator.o&#65533;&#65533;&#65533;&#65533;&#65533; uninstaller.exe
> > hello.cc&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> [license]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; 
> oregonator.oct
> > hello.o&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> [mingw32]&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; 
> README.txt
> >
>
&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> 10 Datei(en)&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; 206.844 
> Bytes
> >
>
&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
> 12 Verzeichnis(se), 23.336.656.896 Bytes frei
> > octave-3.0.2.exe:3:C:\Programme\Octave\3.0.2_gcc-4.3.0
> > > testOrego2
> > ans =&#65533; 0.15625
> > octave-3.0.2.exe:4:C:\Programme\Octave\3.0.2_gcc-4.3.0
> > >
> > &#65533;thanks 
> > --- Tatsuro MATSUOKA <address@hidden> schrieb am Do, 18.12.2008:
> > 
> > Von: Tatsuro MATSUOKA <address@hidden>
> > Betreff: Re: call c++ dlls in octave
> > An: "Michael Goffioul" <address@hidden>, address@hidden
> > CC: address@hidden
> > Datum: Donnerstag, 18. Dezember 2008, 1:58
> > 
> > Hello
> > 
> > The url is described at 
> > the Note of 1.1. Octave-Forge: GNU Octave Repository
> > in
> > http://wiki.octave.org/wiki.pl?OctaveForWindows
> > 
> > You can see it from
> > http://www.tatsuromatsuoka.com/octave/Eng/Win/index.html#0004
> > msvcoct.html,4,602 bytes, 2008-11-25, md5 c76eaead3a6c2fe151403875459d31c4,
> > Note for mkoctfile (and
> > pkg install) for MSVC-octave 3.0.3.
> > 
> > Regards
> > 
> > Tatsuro
> >  
> > --- Michael Goffioul <address@hidden> wrote:
> > > Tatsuro has made a nice page will all information needed
> > > to compile oct-file under Windows (Tatsuro, can you post
> > > the link?).
> > 
> > 
> > 
> > --------------------------------------
> > Power up the Internet with Yahoo! Toolbar.
> > http://pr.mail.yahoo.co.jp/toolbar/
> > 
> > 
> > 
> >       > /* 
> > ------------------------------------------------------------------------ */
> > /* 
> >  * This header declares the public, standard-C interfaces of 
> >  * the TWUClib, the "TEC Web-Umbrella Client" library
> >  *
> >  * Author: Jon Krom, Forschungszentrum Juelich, Institut fuer Plasmaphysik.
> >  * $Id: TWUClib-base.h,v 2.15 2008/11/14 13:20:46 jgk Exp $
> >  * Copyright (c) 2000,...,2008  Forschungszentrum Juelich GmbH.
> >  * All rights reserved.
> >  */
> > /* ------------------------------------------------------------------------ 
> > */
> > 
> > #ifndef TWUCLIBBASE_H
> > #define TWUCLIBBASE_H
> > 
> > #ifdef  __cplusplus
> > extern "C" 
> > {
> > #endif
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     /* Local types and forward declarations */
> > 
> >     struct TWUlinkContext;              /* Open link context */
> > 
> >     typedef struct TWUlinkContext * TWUContext;
> > 
> >     enum TWUClib_Open_Options           /* A bit map of options */
> >     {
> >         TWOO_no_options     = 0,
> >         TWOO_propertiesOnly = 0x1,      /* Pre-fetch at most the properties 
> > */
> >         TWOO_keepHTTPhead   = 0x2,      /* Keep the HTTP header visible     
> > */
> >         TWOO_allowbinary    = 0x4,      /* Allow binary IEEE float 
> > transfers*/
> >         TWOO_dont_fake      = 0x8,      /* Do not fake equidistant signals  
> > */
> >         TWOO_default        = TWOO_allowbinary
> >     };
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     struct TWUlinkContext *
> >     TWUopenURL(
> >         char const *        ,           /* URL */
> >         enum TWUClib_Open_Options );    /* Open options */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> > 
> >     struct TWUlinkContext *             /* Context pointer */
> >     TWUopenSignal2(
> >         char const *,                   /* URL */
> >         char const *,                   /* bulk query string */
> >         char const *,                   /* properties query string */
> >         int );                          /* enum TWUClib_Open_Options  */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     int
> >     TWUhasError(
> >         struct TWUlinkContext const *); /* Context pointer */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     char const *
> >     TWUerrorInfo(
> >         struct TWUlinkContext const *,  /* Context pointer  */
> >         int                         *,  /* Last HTTP status */
> >         char const *                *,  /* TWUerror text (static const)  */
> >         char const *                *); /* errno - text from strerror(3) */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     char const *                        /* ptr to property value */
> >     TWUgetproperty(
> >         struct TWUlinkContext *,        /* Context pointer */
> >         char            const *);       /* Required property keyword */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     char *
> >     TWUgetline(
> >         struct TWUlinkContext *);       /* Context pointer */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     int
> >     TWUgetsingles(
> >         struct TWUlinkContext *,        /* Context pointer */
> >         float *                ,        /* floatArray      */
> >         int                    );       /* floatArraySize  */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     int
> >     TWUgetdoubles(
> >         struct TWUlinkContext *,        /* Context pointer */
> >         double *               ,        /* floatArray      */
> >         int                    );       /* floatArraySize  */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     void
> >     TWUreleaseLink(
> >         struct TWUlinkContext **);      /* Context pointer */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> >     char const *
> >     TWUsetUserAgent(
> >         char const * );                 /* A new "user agent" program name 
> > */
> > 
> >     /* -------------------------------------------------------------------- 
> > */
> > #ifdef  __cplusplus
> > }
> > #endif
> > 
> > #endif /* TWUCLIBBASE_H */
> > /* End of: $Id: TWUClib-base.h,v 2.15 2008/11/14 13:20:46 jgk Exp $ */
> > /* ------------------------------------------------------------------------ 
> > */
> > > /* 
> > > ------------------------------------------------------------------------ 
> > > */
> > /* 
> >  * This file defines the high-level TWU-client operations for 
> >  * opening a TWU-signal URL.
> >  * 
> >  * Author: Jon Krom, Forschungszentrum Juelich, Institut fuer Plasmaphysik.
> >  * $Id: TWUopenSignal.c,v 2.12 2008/11/14 13:20:45 jgk Exp $
> >  * Copyright (c) 2000 Forschungszentrum Juelich GmbH.
> >  * All rights reserved.
> >  *
> >  * For change history use the cvs log command.
> >  */
> > /* ------------------------------------------------------------------------ 
> > */
> > 
> > #include <string.h>
> > 
> > #include "TWUClib.h"
> > #include "TWUClibInternal.h"
> > #include "TWUlinkContext.h"
> > 
> > #ifdef WIN32
> > #   define  LOCALCONST              /* Keep silly Microsoft compiler quiet 
> > */
> > #else
> > #   define  LOCALCONST const        /* Standard-C compilers understand this 
> > */
> > #endif
> > 
> > 
> > /* ------------------------------------------------------------------------ 
> > */
> > struct TWUlinkContext *
> > TWUopenSignal2( char const *              LOCALCONST URL, 
> >                 char const *              LOCALCONST bulk_query,
> >                 char const *              LOCALCONST prop_query,
> >                 int                       LOCALCONST options)
> > {
> >     struct TWUlinkContext * context ;
> > 
> >     if (options & TWOO_propertiesOnly )
> >     {
> >         context = TWUopenURLQ( URL, prop_query, options );
> >     }
> >     else
> >     {
> >         context = TWUopenURLQ( URL, prop_query ? prop_query : "terse", 
> > options );
> >     
> >         TWUcloseLink(context);
> > 
> >         if ( ! TWUhasError(context) &&  
> >              ! fakingPrepared(context, URL, bulk_query, options ) )
> >         {
> >             char const * bulkname = TWUgetproperty( context, "Bulkfile.URL" 
> > );
> > 
> >             if(bulkname)
> >             {
> >                 struct TWUlinkContext * bulkfile ;
> > 
> >                 bulkfile = TWUopenURLQ( bulkname, bulk_query, options);
> >                 bulkfile->associate = context;
> > 
> >                 if (TWUhasError(bulkfile) )
> >                   TWUcloseLink(bulkfile);
> > 
> >                 context = bulkfile;
> >             }
> >         }
> >     }
> >     if ( !(options & TWOO_keepHTTPhead ) && !TWUhasError(context) )
> >       TWUjumpHead(context);
> > 
> >     return context;
> > }
> > 
> > /* ------------------------------------------------------------------------ 
> > */
> > /* Deprecated function - Not to be used anymore
> >  * Only provided here to satisfy linking against user codes 
> >  * that still depend on it.
> >  */
> > struct TWUlinkContext * TWUopenSignal(char const * , char const * , int );
> > 
> > struct TWUlinkContext *
> > TWUopenSignal( char const * LOCALCONST URL, 
> >                char const * LOCALCONST query_str,
> >                int          LOCALCONST options)
> > {
> >     return TWUopenSignal2( URL, query_str, query_str, 
> >                            (enum TWUClib_Open_Options)options);
> > }
> > 
> > 
> > /* ------------------------------------------------------------------------ 
> > */
> > /* End of: $Id: TWUopenSignal.c,v 2.12 2008/11/14 13:20:45 jgk Exp $ */
> > /* ------------------------------------------------------------------------ 
> > */
> > 
> 
> 
> --- Michael Goffioul <address@hidden> wrote:
> 
> > Octave does not support loadlibrary and related.
> > To call functions from a DLL, you need to wrap the function
> > into an oct-file. This is rather easy to do and there exist
> > some examples in octave source tree (this has been
> > mentioned before on this mailing list, you might want
> > to search through previous posts).
> > 
> > To build an oct-file, you obviously need a compiler.
> > As you're probably using the precompiled version
> > from octave-forge, you'll need the Visual C++ 2008
> > compiler (available free of charge from MS web site).
> > Tatsuro has made a nice page will all information needed
> > to compile oct-file under Windows (Tatsuro, can you post
> > the link?).
> > 
> > Michael.
> > 
> > 
> > On Wed, Dec 17, 2008 at 7:45 AM, Allahyari Rahim <address@hidden> wrote:
> > > Hi,
> > > i want to call my dll with octave 3.0.3
> > > but i don't know how can i solve this problem.
> > > i have used dll in Matlab like this
> > >
> > > " myPath = 'C:\TWUClib\Win32\lib';
> > >   hfile =  'C:\TWUClib\Win32\include\TWUClib-base.h';
> > >   loadlibrary([myPath '\TWUClib'],hfile);
> > >   signal=calllib('TWUClib','TWUopenSignal2',url,'','',TWOO_default);
> > > "
> > > i tried to use mkoctfile to build oct file.and ... but can't continue.
> > > can anybody help me.
> > > thanks
> > > Allahyari
> > >
> > > _______________________________________________
> > > Help-octave mailing list
> > > address@hidden
> > > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> > >
> > >
> > _______________________________________________
> > Help-octave mailing list
> > address@hidden
> > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> > 
> 
> 
> --------------------------------------
> Power up the Internet with Yahoo! Toolbar.
> http://pr.mail.yahoo.co.jp/toolbar/
> 


--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/


reply via email to

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