help-octave
[Top][All Lists]
Advanced

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

Re: Octave / cygwin / dynamic linking - success


From: Paul Kienzle
Subject: Re: Octave / cygwin / dynamic linking - success
Date: Sun, 8 Sep 2002 15:18:57 -0400

I haven't looked at the details of what you've done, but I successfully
built a lite-kernel version of octave yesterday, and spent last night 
trying to update the configure scripts to do it automatically.  Here is
what I came up with.

The biggest change is that DLLs need to be linked against all their
dependencies, so a number of changes are required throughout the build
system.  I define the flag INCLUDE_LINK_DEPS for this so that individual
Makefiles can define LINK_DEPS appropriately for the library being built.

There was a circular dependency between liboctave and liboct-readline 
via str-vec.cc.  I removed this by combining liboctave and liboct-*.
It isn't necessary to include liboct-pathsearch in liboctave, but I
did it anyway.

The readline library needs to be linked into liboctave.dll instead of
octave.exe, which means including it in the LIBS variable is insufficient.

I don't pick up all dynamic libraries on the system automatically.  To link
against a dynamic library the link command needs -lxxx.dll rather than
-lxxx.

* hdf5, lapack, and blas can be specified in configure:
    ./configure --with-xxx=-lxxx.dll

* ncurses isn't required since cygwin's readline is already linked against it.
    
* readline uses the static version.  This could be fixed in the 
  OCTAVE_ENABLE_READLINE defined in aclocal.m4.  Static linking may be
  prefered however since we don't have version numbers to protect us from
  DLL hell.

DLLs must be installed in the bin directory and a new file, libxxx.dll.a,
must be installed in the lib directory.  I call these the load and link
forms respectively.  I tag them with SHLBIN and SHLLIB which I define in
configure.

Although the C++ compiler prepends an underscore, cygwin's dlsym
automatically adds it, so the configure test for CXX_PREPENDS_UNDERSCORE in
aclocal.m4 is leading us astray.

AFAIK, version numbers aren't supported in cygwin.  I'm installing the file
with version numbers anyway to make the Makefiles simpler.  I made the
non-versioned target the principle target.  I don't know if this will break
Unix builds.  Does ld store the output file name anywhere in the shared
library?

I haven't touched bin-dist rules or the corresponding install-octave.  They
will be broken for cygwin.

I haven't run make check (I don't believe it is possible on Win 9x since
expect won't run).  To run make check or otherwise check octave in situ all
the DLLs must be on the path or in the current directory.  I just copied
the DLLs to src, but symbolic links to liboctave and libcruft may work.

I'm still testing the patch.  With compiles taking hours, this is a tedious
process.

Paul Kienzle <address@hidden>

ChangeLog:


octave/ChangeLog

    * configure.in: Use correct SHLEXT and PICFLAG for cygwin.
    * configure.in: Cygwin must link against -loctave.dll, etc.

    * configure.in: Define INCLUDE_LINK_DEPS because cygwin needs DLLs to
    be linked against their dependencies.
    * Makeconf.in: Ditto.

    * configure.in: Define SHLLIB and SHLBIN because cygwin doesn't link
    against shared libs but instead against -lxxx.dll. LIB and BIN are
    the link and load forms respectively of the library.
    * Makeconf.in: Ditto, and define the corresponding XXX_VER.

    * configure.in: Remove LIBOCT_READLINE and LIBOCT_PATHSEARCH because 
    they are merged into LIBOCTAVE to avoid circular dependencies.
    * Makeconf.in: Ditto.
    * mkoctfile.in: Ditto.
    
    * aclocal.m4: Define LIBREADLINE because cygwin requires liboctave to
    be linked against -lreadline so including it in LIBS isn't sufficient.
    * mkoctfile.in: Ditto.

    * aclocal.m4: Force CXX_PREPENDS_UNDERSCORE to no for cygwin.

libcruft/ChangeLog

    * Makefile.in: Specify link dependencies for shared libs if 
INCLUDE_LINK_DEPS.
    * Makefile.in: Make the unversioned library the main build target.
    * Makefile.in: (Un)Install link and load forms of the library separately.

liboctave/ChangeLog

    * Makefile.in: Merge liboctave with liboct-readline and liboct-pathsearch.
    * Makefile.in: Specifiy link dependencies for shared libs if 
INCLUDE_LINK_DEPS.
    * Makefile.in: Make the unversioned library the main build target.
    * Makefile.in: (Un)Install link and load forms of the library separately.

src/ChangeLog

    * Makefile.in: Merge liboctave with liboct-readline and liboct-pathsearch.
    * Makefile.in: Specify link dependencies for shared libs if 
INCLUDE_LINK_DEPS.
    * Makefile.in: Make the unversioned library the main build target.
    * Makefile.in: (Un)Install link and load forms of the library separately.
    * toplev.cc: Remove liboct_readline and liboct_pathsearch.

On Sun, Sep 08, 2002 at 09:23:21AM -0400, Andy Adler wrote:
> I've finally figured out how to get dynamically loaded functions working
> under octave on windows. The essense of the method is to separate
> octave into a stub *exe and a *dll with all the functionality. Then
> all *oct files are linked to this dll as well.
> 
> The following recipe gives the steps I took.
> 
> I'd like some comments on:
> 
> 1. Are there simpler ways to do this.
> 2. Does this work on all flavours of windows.
> 3. Is is possible to propose patches like this for the main octave tree.
> 
> Currently this octave.exe gives a windows segmentation fault
> when the program terminates. I haven't looked into this but it
> shouldn't be too hard to solve
> 
> --
> Andy Adler (address@hidden)
> 
> 
> Instructions to get octave-2.1.36 to support
> DLD functions under cygwin.
> 
> 1. Download octave-2.1.36.tar.bz
> 
> 2. in /usr/src/octave
>   tar xvfj /path/to/octave-2.1.36.tar.bz2
> 
> 3. cd octave-2.1.36
>  ./configure --prefix=/usr/local/octave-2.1.36-dltest/ \
>      --enable-static --enable-dl
> 
> 4. EDIT config.h
>  comment out line:  #define CXX_PREPENDS_UNDERSCORE
> 
> (I think that even though the c++ puts the underscore,
>  the windows LoadLibrary call will remove it by itself )
> 
> 5. EDIT src/defun-int.h
>  look for DEFINE_FUN_INSTALLER_FUN3
> 
>  change line: return error_state ? false : true;
>  to:          return true;
> 
> ( I have no idea why this is necessary, I traced
>   error_state throughout the call stack for
>   dynamic loading, and somewhere it suddenly
>   became non-zero ... )
> 
> 6. BUILD AND INSTALL OCTAVE NORMALLY 
>    BUT THEN REMOVE THE INSTALLED octave*.exe
> 
>    make
>    make install
>    rm /usr/local/octave-2.1.36-dltest/bin/octave-2.1.36.exe
> 
> 7. CREATE octave-dll.cc
> 
>    cp src/octave.cc src/octave-dll.cc
>    EDIT src/octave-dll.cc
>    CHANGE line   main(int argc, char **argv)
>    TO            octavedllmain(int argc, char **argv)
> 
> 
> 8. MODIFY THE MAKEFILE TO BUILD octave-2.1.36.dll  
> 
> ADD THE FOLLOWING RULE TO: src/Makefile
> AFTER THE RULE: octave:
> 
> octave-2.1.36.dll: stamp-prereq $(LIBRARIES) stamp-oct-links \
>     octave-dll.o builtins.o ops.o $(DLD_STATIC_OBJ)
>     $(LD_CXX) $(CPPFLAGS) $(ALL_CXXFLAGS) $(RDYNAMIC_FLAG) \
>     $(ALL_LDFLAGS) -shared -o $@ \
>     octave-dll.o builtins.o ops.o $(XERBLA) $(DLD_STATIC_OBJ) \
>     $(OCTAVE_LFLAGS) \
>     $(OCTAVE_LIBS) \
>     $(LEXLIB) $(BLAS_LIBS) $(FFTW_LIBS) $(LIBS) $(FLIBS)
> 
> 9. BUILD octave-2.1.36.dll
> 
> IN src: make octave-2.1.36.dll
> 
> 10. CREATE FILE: octave-calldll.cc
> 
> IN src:
> cat > octave-call.dll.cc
>   int dllmain (int argc, char **argv);
>   int main (int argc, char **argv) {
>     return octavedllmain(argc,argv);
>   }
> ^D
> 
> 11. BUILD octave-calldll.exe
> 
> IN src:
> c++ octave-calldll.cc octave-2.1.36.dll -o octave-calldll.exe
> 
> 12. COPY FILES TO BIN DIR
>    cp octave-calldll.exe 
> /usr/local/octave-2.1.36-dltest/bin/octave-2.1.36.exe
>    cp octave-2.1.36.dll /usr/local/octave-2.1.36-dltest/bin/
> 
> 13. MODIFY MKOCTFILE
>    EDIT /usr/local/octave-2.1.36-dltest/bin/mkoctfile-2.1.36
> 
>    MODIFY LINE (near end)
> 
>    cmd="$SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags"
> 
>    TO
> 
>    cmd="$SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags 
> /usr/local/octave-2.1.36-dltest/bin/octave-2.1.36.dll"
> 
> 14. USING OCTAVE EXAMPLE
> 
> $ uname -a
> CYGWIN_NT-5.1 ANALYTI1 1.3.10(0.51/3/2) 2002-02-25 11:14 i686 unknown
> 
> $ ls -l /usr/local/octave-2.1.36-dltest/bin/
> -rwxr-xr-x    1 andy     None         9704 Sep  8 08:59 mkoctfile-2.1.36
> -rwxr-xr-x    1 andy     None     34388927 Sep  8 08:51 octave-2.1.36.dll
> -rwxr-xr-x    1 andy     None        18446 Sep  8 08:51 octave-2.1.36.exe
> 
> $ strip /usr/local/octave-2.1.36-dltest/bin/octave-2.1.36.*
> $ ls -l /usr/local/octave-2.1.36-dltest/bin/
> -rwxr-xr-x    1 andy     None         9704 Sep  8 08:59 mkoctfile-2.1.36
> -rwxr-xr-x    1 andy     None      7029248 Sep  8 09:12 octave-2.1.36.dll
> -rwxr-xr-x    1 andy     None         3072 Sep  8 09:12 octave-2.1.36.exe
> 
> $ cd /usr/src/octave/octave-2.1.36-trydlinking/examples
> $ /usr/local/octave-2.1.36-dltest/bin/mkoctfile hello.cc
> cc1plus.exe: warning: -fPIC ignored for target (all code is position ...
> 
> $ ls -l hello.oct
> -rwxr-xr-x    1 andy     None       517578 Sep  8 09:13 hello.oct
> $ strip hello.oct
> $ ls -l hello.oct
> -rwxr-xr-x    1 andy     None       114688 Sep  8 09:15 hello.oct
> 
> $ /usr/local/octave-2.1.36-dltest/bin/octave -q
> octave:1> help hello
> hello is the dynamically-linked function from the file
> /usr/src/octave/octave-2.1.36-trydlinking/examples/hello.oct
> [...] = hello (...)
> etc...
> 
> octave:2> [a,b,c]=hello(1,2,3)
> Hello, world!
> 1
> 2
> 3
> a = 3
> b = 2
> c = 1
> octave:3> exit
> 
> 
> 
> 
> 
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
> 



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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