[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Octave / cygwin / dynamic linking - success
From: |
Andy Adler |
Subject: |
Octave / cygwin / dynamic linking - success |
Date: |
Sun, 08 Sep 2002 09:23:21 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.0) Gecko/20020530 |
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 / cygwin / dynamic linking - success,
Andy Adler <=