Wow, this one was very hard to fix!
from tools/swilena/ChangeLog
2007-02-17 Roland Levillain <roland(a)lrde.epita.fr>
Fix Rblena on Mac OS X.
Note that you have to set the envvar MACOSX_DEPLOYMENT_TARGET to
10.3 for this to work.
* expand.sh (AM_LDFLAGS) [DARWIN]: Add`-no-undefined
-Wl,-twolevel_namespace -Wl,-undefined -Wl,dynamic_lookup' for
Ruby wrappers, so as to generate two-level namespace (to avoid
name clashes at load time).
* TODO: Update.
--- 10.296/tools/swilena/expand.sh Sat, 10 Feb 2007 16:31:23 +0100 levill_r
(oln/s/25_expand.sh 1.22 744)
+++ 10.297/tools/swilena/expand.sh Sat, 17 Feb 2007 11:33:33 +0100 levill_r
(oln/s/25_expand.sh 1.23 744)
@@ -255,8 +255,73 @@
AM_CPPFLAGS = -DOLN_EXCEPTIONS \$(RUBY_CPPFLAGS) \\
-I\$(srcdir)/../src -I\$(srcdir)/../meta
AM_CXXFLAGS = \$(CXXFLAGS_OPTIMIZE) \$(DOC_CPPFLAGS)
+
## We build modules, not plain libs.
AM_LDFLAGS = -avoid-version -module -shared \$(ZLIB_LDFLAGS)
+
+# On Mac OS X, the Ruby interpreter accepts only files ending in
+# \`.bundle\' (and \`.rb\' of course). Tell Libtool to use the
+# \`.bundle\' extension instead of the default \`.so\'.
+#
+# Moreover, the way the Ruby interpreter uses dynamic module (on Mac
+# OS X) is far less tolerant than Python w.r.t. multiply defined
+# symbols. The thing is, unless told to do otherwise, Libtool creates
+# flat-namespace modules, which produce name clashes, because some
+# symbols are defined multiple times (for instance, the symbol for
+# \`oln::image2d\' is provided by \`swilena_image2.la\' and
+# \`swilena_arith2d.la').
+#
+# The nightmare of dynamic modules with multiply defined symbols on Mac OS X.
+# ---------------------------------------------------------------------------
+#
+# To avoid errors on multiply defined symbols, we can use two-level
+# namespaces (see the man page of \`ld\' on Mac OS X). The drawback is
+# that until Mac OS X 10.3 (Panther), two-level namespaces
+# libraries/modules do not allow undefined symbols, which is a pain in
+# our case, since our modules needs symbols provided by the Ruby
+# environment. Anyway, Mac OS X 10.3 solved this with the linker flag
+# \`-undefined dynamic_lookup\', postponing the resolution of undefined
+# symbols at runtime Since this flag breaks the compatibility with
+# previous versions of Mac OS X, the linker requires the environment
+# variable MACOSX_DEPLOYMENT_TARGET to be to \`10.3\'. Another glitch is
+# the way Libtool interprets the options it gets passed. One could
+# imagine that adding
+#
+# -twolevel_namespace -undefined dynamic_lookup
+#
+# or
+#
+# -Wl,-twolevel_namespace -Wl,-undefined -Wl,dynamic_lookup
+#
+# to AM_LDFLAGS would be sufficient for Libtool to understand that we
+# want to create a two-level namespace module with dynamic lookup.
+# Alas, things are not that simple. In fact Libtool still forces the
+# creation of a flat namespace module, in spite of the
+# \`-twolevel_namespace\' option.
+#
+# The solution is to insert the flag \`-no-undefined\' first, which turns
+# off flat namespaces, then to pass the options above. And it works,
+# at last!
+#
+# Just remember:
+#
+# You must set MACOSX_DEPLOYMENT_TARGET=10.3
+# in the environment for this to work!
+#
+# (Setting it to 10.4 on Mac OS X 10.4 (Tiger) might work as well,
+# but it has not been tested yet.)
+#
+# This solution was set up thanks to clues from the Libtool mailing list:
+#
+#
http://www.mail-archive.com/libtool@gnu.org/msg05785.html
+#
http://www.mail-archive.com/libtool@gnu.org/msg06952.html
+#
http://lists.gnu.org/archive/html/libtool/2004-10/msg00090.html
+#
http://lists.gnu.org/archive/html/libtool/2005-03/msg00061.html
+#
+if DARWIN
+ AM_LDFLAGS += -shrext .bundle \\
+ -no-undefined -Wl,-twolevel_namespace -Wl,-undefined -Wl,dynamic_lookup
+endif DARWIN
AM_SWIG_FLAGS = -c++ -ruby \$(AM_CPPFLAGS)
EOF
}
--- 10.296/tools/swilena/TODO Sat, 27 Sep 2003 19:02:23 +0200 burrus_n (oln/n/36_TODO 1.3
644)
+++ 10.297/tools/swilena/TODO Sat, 17 Feb 2007 11:33:33 +0100 levill_r (oln/n/36_TODO 1.4
644)
@@ -1,15 +1,124 @@
-
+ -*- outline -*-
* Top
-** Simplify algorithm declaration (in the same spirit than
- generate_morpho_instantiations.py)
+** Avoid template instantiation directly in SWIG wrappers.
+(And hence avoid re-compiling the same things over and over!)
+Because :
+- it's a waste of time;
+- and even more important, it creates duplicated code (and symbols) in
+ generated wrappers, sometimes causing real pain at load time.
+
+
+FIXME: Move the following diagrams into Swilena's doc.
+
+Let's see how SWIG was meant to be used, with e.g., Python or Ruby and
+C++ libraries.
+
+----------------------------------------------------------------------
+ Client | SWIG wrapper | Wrapped library
+----------------------------------------------------------------------
+ | |
+ SWIG interface read Library header
+ | (foo.i) --------> (foo.hh)
+ |
+ | v |
+ ,----------------.
+ | | SWIG generator | |
+ | (swig) |
+ | `----------------' |
+ |
+ | v |
+ C++ wrapper
+ | (foo_wrap.cc) |
+ and optionally a
+ | script wrapper[1] |
+ |
+ | v |
+ ,--------------.
+ | | C++ compiler | link Library code, as
+ | and linker | ------> a dynamic library
+ | | (g++) | | (foo.so[2])
+ `--------------'
+ | | |
+ v
+ interpreter load Compiled wrapper, |
+ (python/ruby) ----> as a dynamic module
+ | (foo_wrap.so[3]) |
+
+----------------------------------------------------------------------
+
+
+But with Olena, as everything is generic and expressed as templates,
+there are no actual compiled library code provided (i.e., foo.so)! In
+fact, the SWIG interface file does these instantiations of the wrapped
+templates _inside_ the C++ wrapper itself!
+
+----------------------------------------------------------------------
+ Client | SWIG wrapper | Wrapped library
+----------------------------------------------------------------------
+ | read &
+ SWIG interface include Library header
+ | (foo.i) --------> (foo.hh,
+ | foo.hxx)
+ | v |
+ ,----------------.
+ | | SWIG generator | |
+ | (swig) |
+ | `----------------' |
+ |
+ | v |
+ C++ wrapper[4]
+ | (foo_wrap.cc) |
+ and optionally a
+ | script wrapper[1] |
+ |
+ | v |
+ ,--------------.
+ | | C++ compiler | |
+ | and linker |
+ | | (g++) | |
+ `--------------'
+ | | |
+ v
+ interpreter load Compiled wrapper, |
+ (python/ruby) ----> as a dynamic module
+ | (foo_wrap.so[3]) |
+
+----------------------------------------------------------------------
+
+This is quite annoying, since each generated wrapper (*_wrap.cc) may
+share some class or function definitions, which get in turn compiled
+several times (once per wrapper), and might even cause load errors
+when used together (this is the case by default with Ruby on Mac OS X,
+unless the linkage of the wrapper is done carefully -- see how
+`expand.sh' handles this with AM_LDFLAGS).
+
+
+=> So, it would be wise to create C++ dynamic libraries in Swilena,
+ and then to wrap them with swig.
+
+
+Notes:
+[1] Swig creates a small glue in Python in addition to the C++
+wrapper, and this wrapper serves as an interface between the Python
+interpreter and the dynamic module.
+As for Ruby, the interpreter directly uses the dynamic module.
+
+[2] foo.dylib on Mac OS X.
+
+[3] foo_wrap.bundle on Mac OS X.
+
+[4] Contains the wrapped code, in addition to the wrapper!
+
+
+** Simplify algorithm declaration
+ (in the same spirit as generate_morpho_instantiations.py)
** Bind other stuff from Olena.
-** Typemaps for integre types
+** Typemaps for Integre types
** Document.
** More examples.
* Medium
-** Improve ruby support
** Compile to Perl.
** Think about compiling to Caml.
--- 10.296/ChangeLog Fri, 16 Feb 2007 19:44:00 +0100 levill_r (oln/o/33_ChangeLog
1.37.1.16.1.17.1.19.1.39 644)
+++ 10.297/ChangeLog Sat, 17 Feb 2007 11:33:33 +0100 levill_r (oln/o/33_ChangeLog
1.37.1.16.1.17.1.19.1.40 644)
@@ -1,3 +1,7 @@
+2007-02-17 Roland Levillain <roland(a)lrde.epita.fr>
+
+ * configure.ac (DARWIN): New Automake conditional.
+
2007-02-16 Roland Levillain <roland(a)lrde.epita.fr>
Fix the distribution mechanism.
--- 10.296/configure.ac Fri, 09 Feb 2007 18:31:11 +0100 levill_r (oln/3_configure.
1.47.1.1.1.1.1.4.1.15.1.16.1.15 644)
+++ 10.297/configure.ac Sat, 17 Feb 2007 11:33:33 +0100 levill_r (oln/3_configure.
1.47.1.1.1.1.1.4.1.15.1.16.1.16 644)
@@ -54,6 +54,9 @@
# Use Libtool to build Swilena's dynamic modules.
AC_PROG_LIBTOOL
+# Check for Darwin to help Libtool use the right dynamic module
+# extension on this system.
+AM_CONDITIONAL([DARWIN], [echo "$host_os" | grep '^darwin'])
# If available, use these.
AC_WITH_CXX_ZLIB
--- 10.296/oln.prj
+++ 10.297/oln.prj
@@ -1,17 +1,23 @@
;; -*- Prcs -*-
(Created-By-Prcs-Version 1 3 3)
(Project-Description "Olena")
-(Project-Version oln 10 296)
-(Parent-Version oln 10 295)
-(Version-Log "2007-02-16 Roland Levillain <roland(a)lrde.epita.fr>
+(Project-Version oln 10 297)
+(Parent-Version oln 10 296)
+(Version-Log "2007-02-17 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Fix Rblena on Mac OS X.
+ Note that you have to set the envvar MACOSX_DEPLOYMENT_TARGET to
+ 10.3 for this to work.
+
+ * expand.sh (AM_LDFLAGS) [DARWIN]: Add`-no-undefined
+ -Wl,-twolevel_namespace -Wl,-undefined -Wl,dynamic_lookup' for
+ Ruby wrappers, so as to generate two-level namespace (to avoid
+ name clashes at load time).
+ * TODO: Update.
- Fix the distribution mechanism.
-
- * Makefile.am (EXTRA_DIST): Remove config/strip-lrde.
- (dist-hook): Prune bootstrap.sh *after* using it.
")
(New-Version-Log "")
-(Checkin-Time "Fri, 16 Feb 2007 19:44:00 +0100")
+(Checkin-Time "Sat, 17 Feb 2007 11:33:33 +0100")
(Checkin-Login levill_r)
;; diff-ignore tests/data/.*pbm$
;; diff-ignore .*\.pbm$
@@ -124,13 +130,13 @@
(Project-Keywords)
(Files
- (ChangeLog (oln/o/33_ChangeLog 1.37.1.16.1.17.1.19.1.39 644))
+ (ChangeLog (oln/o/33_ChangeLog 1.37.1.16.1.17.1.19.1.40 644))
(doc/ChangeLog (oln/o/31_ChangeLog 1.38.1.7.1.5.1.14.1.24 644))
(integre/ChangeLog (oln/q/35_ChangeLog 1.12.1.2.1.56 755))
(metalic/ChangeLog (oln/q/30_ChangeLog 1.3.1.48 644))
(olena/ChangeLog (oln/o/30_ChangeLog
1.27.1.36.1.3.1.11.1.5.1.64.1.47.1.93.1.27.2.18.1.19 644))
(tools/ChangeLog (oln/o/32_ChangeLog 1.10.1.20 644))
- (tools/swilena/ChangeLog (oln/n/37_ChangeLog 1.7.1.55 644))
+ (tools/swilena/ChangeLog (oln/n/37_ChangeLog 1.7.1.56 644))
(olena/ChangeLog.0 (oln/6_ChangeLog 1.50.1.98.1.5 644))
(doc/ChangeLog.0 (oln/e/1_ChangeLog 1.31 644))
@@ -140,7 +146,7 @@
(cleanup.sh (oln/o/29_cleanup.sh 1.7 755))
- (configure.ac (oln/3_configure. 1.47.1.1.1.1.1.4.1.15.1.16.1.15 644))
+ (configure.ac (oln/3_configure. 1.47.1.1.1.1.1.4.1.15.1.16.1.16 644))
(doc/demo/image.cc (oln/d/46_image.cc 1.9 644))
(doc/demo/Makefile.am (oln/d/44_Makefile.a 1.16.1.3 644))
@@ -597,7 +603,7 @@
(tools/swilena/meta/attic/swilena_window.i (oln/o/9_swilena_wi 1.1 644))
(tools/swilena/meta/attic/swilena_w_window.i (oln/o/6_swilena_w_ 1.1 644))
; (tools/swilena/swilena.prj (oln/n/38_swilena.pr 1.1 640))
- (tools/swilena/TODO (oln/n/36_TODO 1.3 644))
+ (tools/swilena/TODO (oln/n/36_TODO 1.4 644))
(tools/utilities/configure.ac (oln/o/27_configure. 1.3 644))
(tools/utilities/Makefile.am (oln/g/2_Makefile.a 1.12.1.6 644))
(tools/utilities/morpho/generate_morpho.sh (oln/i/30_generate_m 1.3.1.5.1.3 744))
@@ -864,7 +870,7 @@
;; Files added by populate at Tue, 06 May 2003 06:05:19 +0200,
;; to version 8.33(w), by raph:
- (tools/swilena/expand.sh (oln/s/25_expand.sh 1.22 744))
+ (tools/swilena/expand.sh (oln/s/25_expand.sh 1.23 744))
;; Files added by populate at Tue, 06 May 2003 06:05:41 +0200,
;; to version 8.33(w), by raph: