Problem compiling extension on Solaris

I have an user who is trying to build RMagick on Solaris with Ruby 1.6.8.
The Makefile is generated by extconf.rb. The link fails with these
messages:

gcc -V 3.3 -Wl,-G -L/usr/local/lib -Wl,-rpath,/usr/local/lib
-L/usr/local/lib -L/usr/local/lib -R/usr/local/lib -L/usr/openwin/lib
-R/usr/openwin/lib -L/usr/local/lib -L/usr/local/lib -o RMagick.so
rmfill.o rmilist.o rmimage.o rminfo.o rmmain.o rmutil.o -L. -lruby -lc
-ldl -lcrypt -lm -lGraphicsMagick -ljbig -llcms -ltiff -lfreetype
-ljasper -ljpeg -lpng -lfpx -lwmflite -ldpstk -ldps -lXext -lSM -lICE
-lX11 -lsocket -lnsl -lbz2 -lxml2 -lz -lpthread -lm
ld: fatal: option -dn and -P are incompatible
ld: fatal: option -dn and -G are incompatible
ld: fatal: Flags processing errors
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `RMagick.so

In order to successfully build RMagick, he used this command:

% gcc -V 3.3 -shared -L/usr/local/lib -L/usr/local/lib
-R/usr/local/lib -L/usr/openwin/lib -R/usr/openwin/lib
-L/usr/local/lib -L/usr/local/lib -L"/usr/local/lib" -o RMagick.so
rmfill.o rmilist.o rmimage.o rminfo.o rmmain.o rmutil.o -ldl -lcrypt
-lm -lGraphicsMagick -ljbig -llcms -ltiff -lfreetype -ljasper -ljpeg
-lpng -lfpx -lwmflite -ldpstk -ldps -lXext -lSM -lICE -lX11 -lsocket
-lnsl -lbz2 -lxml2 -lz -lpthread -lm -lc

What are the -dn, -P, and -G flags used for and why are they being added
to the gcc command? Is there a bug in extconf.rb on Solaris?

I can provide the extconf.rb script on request.

Hi,

···

In message “Problem compiling extension on Solaris” on 03/05/26, “Tim Hunter” cyclists@nc.rr.com writes:

I have an user who is trying to build RMagick on Solaris with Ruby 1.6.8.
The Makefile is generated by extconf.rb. The link fails with these
messages:

Sorry, I have no clue. We don’t use -P nor -dn, at least
explicitly. We need Solaris guru to solve this question.

						matz.

Thanks, Matz. Sadly, this was reported to me by a Solaris guru. He
suggested that we ask a Ruby guru :frowning:

I misstated the Ruby release. This is Ruby 1.8.0preview2. I believe the -P
and -dn flags are being added by the Solaris gcc linker driver. (Note that
this is gcc 3.3.) The -dn option is for static linking only. The -G option
is for shared linking only. Is it possible that this is the result some
confusion between building static and shared modules?

For reference I am appending the entire Makefile.

SHELL = /bin/sh

Start of system configuration section.

srcdir = /home/bfriesen/src/lang/RMagick-1.2.2beta1/ext/RMagick
topdir = $(rubylibdir)/$(arch)
hdrdir = $(rubylibdir)/$(arch)
VPATH = $(srcdir)
prefix = $(DESTDIR)/usr/local
exec_prefix = $(prefix)
sitedir = $(prefix)/lib/ruby/site_ruby
rubylibdir = $(libdir)/ruby/$(ruby_version)
builddir = $(ac_builddir)
archdir = $(rubylibdir)/$(arch)
sbindir = $(exec_prefix)/sbin
compile_dir = $(DESTDIR)/home/bfriesen/src/lang/ruby-1.8.0
datadir = $(prefix)/share
includedir = $(prefix)/include
infodir = $(prefix)/info
top_builddir = $(ac_top_builddir)
sysconfdir = $(prefix)/etc
mandir = $(prefix)/man
libdir = $(exec_prefix)/lib
sharedstatedir = $(prefix)/com
oldincludedir = $(DESTDIR)/usr/include
sitearchdir = $(sitelibdir)/$(sitearch)
bindir = $(exec_prefix)/bin
localstatedir = $(prefix)/var
sitelibdir = $(sitedir)/$(ruby_version)
libexecdir = $(exec_prefix)/libexec

CC = gcc -V 3.3
LIBRUBY = $(LIBRUBY_A)
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
LIBRUBYARG_SHARED =
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static

CFLAGS = -fPIC -Wall -O2 -g -Wall -I/usr/local/include -I/usr/local/include/freetype2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT -I/usr/openwin/include -I/usr/openwin/include/X11 -I/usr/local/include/libxml2 -DRUBY_VERSION=0x180
CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
CXXFLAGS = $(CFLAGS)
DLDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib -L/usr/local/lib -R/usr/local/lib -L/usr/openwin/lib -R/usr/openwin/lib -L/usr/local/lib -L/usr/local/lib
LDSHARED = $(CC) -Wl,-G
AR = ar
EXEEXT =

RUBY_INSTALL_NAME = ruby
RUBY_SO_NAME = $(RUBY_INSTALL_NAME)
arch = sparc-solaris2.9
sitearch = sparc-solaris2.9
ruby_version = 1.8
RUBY = ruby
RM = $(RUBY) -rftools -e “File::rm_f(*ARGV.map do|x|Dirend.flatten.uniq)”
MAKEDIRS = $(RUBY) -r ftools -e ‘File::makedirs(*ARGV)’
INSTALL_PROG = $(RUBY) -r ftools -e ‘File::install(ARGV[0], ARGV[1], 0755, true)’
INSTALL_DATA = $(RUBY) -r ftools -e ‘File::install(ARGV[0], ARGV[1], 0644, true)’

End of system configuration section.

LIBPATH = -L"$(libdir)"
DEFFILE =

CLEANFILES =
DISTCLEANFILES =

target_prefix =
LOCAL_LIBS =
LIBS = -ldl -lcrypt -lm -lMagick -ljbig -llcms -ltiff -lfreetype -ljasper -ljpeg -lpng -lfpx -lwmflite -ldpstk -ldps -lXext -lSM -lICE -lX11 -lsocket -lnsl -lbz2 -lxml2 -lz -lpthread -lm -lc
OBJS = rmfill.o rmilist.o rmimage.o rminfo.o rmmain.o rmutil.o
TARGET = RMagick
DLLIB = $(TARGET).so

RUBYCOMMONDIR = $(sitedir)$(target_prefix)
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
RUBYARCHDIR = $(sitearchdir)$(target_prefix)

CLEANLIBS = “$(TARGET).{lib,exp,il?,tds,map}” $(DLLIB)
CLEANOBJS = “*.{o,a,s[ol],pdb,bak}”

all: $(DLLIB)

clean:
@$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)

distclean: clean
@$(RM) Makefile extconf.h conftest.* mkmf.log
@$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)

realclean: distclean
install: $(RUBYARCHDIR)
install: $(RUBYARCHDIR)/$(DLLIB)
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) $(RUBYARCHDIR)
@$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
$(RUBYARCHDIR):
@$(MAKEDIRS) $(RUBYARCHDIR)

site-install: install

…SUFFIXES: .c .cc .m .cxx .cpp .C .o

…cc.o:
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<

…cpp.o:
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<

…cxx.o:
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<

…C.o:
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<

…c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<

$(DLLIB): $(OBJS)
@-$(RM) $@
$(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $(DLLIB) $(OBJS) $(LOCAL_LIBS) $(LIBS)

···

On Mon, 26 May 2003 17:25:48 +0900, Yukihiro Matsumoto wrote:

Hi,

In message “Problem compiling extension on Solaris” > on 03/05/26, “Tim Hunter” cyclists@nc.rr.com writes:

I have an user who is trying to build RMagick on Solaris with Ruby
1.6.8. The Makefile is generated by extconf.rb. The link fails with
these messages:

Sorry, I have no clue. We don’t use -P nor -dn, at least explicitly. We
need Solaris guru to solve this question.

  					matz.

Hi,

Thanks, Matz. Sadly, this was reported to me by a Solaris guru. He
suggested that we ask a Ruby guru :frowning:

:-<

I misstated the Ruby release. This is Ruby 1.8.0preview2. I believe the -P
and -dn flags are being added by the Solaris gcc linker driver. (Note that
this is gcc 3.3.) The -dn option is for static linking only. The -G option
is for shared linking only. Is it possible that this is the result some
confusion between building static and shared modules?

How can I stop -dn option? I want to make shared library, no static
linking sought. Could you ask your Solaris guru nearby?

						matz.
···

In message “Re: Problem compiling extension on Solaris” on 03/05/26, “Tim Hunter” cyclists@nc.rr.com writes:

Hi,

···

At Tue, 27 May 2003 03:46:25 +0900, Yukihiro Matsumoto wrote:

I misstated the Ruby release. This is Ruby 1.8.0preview2. I believe the -P
and -dn flags are being added by the Solaris gcc linker driver. (Note that
this is gcc 3.3.) The -dn option is for static linking only. The -G option
is for shared linking only. Is it possible that this is the result some
confusion between building static and shared modules?

How can I stop -dn option? I want to make shared library, no static
linking sought. Could you ask your Solaris guru nearby?

Seems to need -shared option, according to [ruby-talk:72134].


Nobu Nakada

HI,

How can I stop -dn option? I want to make shared library, no static
linking sought. Could you ask your Solaris guru nearby?

Seems to need -shared option, according to [ruby-talk:72134].

Hmm, I don’t know how to fix this. According to configure.in,

case “$target_os” in
solaris*) if test “$GCC” = yes; then
LDSHARED=‘$(CC) -Wl,-G’
if test “$rb_cv_prog_gnu_ld” = yes; then
LDFLAGS=“-Wl,-E”
LDSHARED=“$LDSHARED -shared”
fi
else
LDSHARED=‘ld -G’
fi
rb_cv_dlopen=yes;;
esac

so that if he was using GNU ld, link line should be

gcc -V 3.3 -Wl,-G -shared -L/usr/local/lib

but it wasn’t. It seemed that configure failed to detect GNU ld,
right? Probably we need to fix RUBY_PROG_GNU_LD macro.

Tim, could you show us how did you run configure script?

						matz.
···

In message “Re: Problem compiling extension on Solaris” on 03/05/27, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

Yukihiro Matsumoto wrote:

HI,

How can I stop -dn option? I want to make shared library, no static
linking sought. Could you ask your Solaris guru nearby?

Seems to need -shared option, according to [ruby-talk:72134].

Hmm, I don’t know how to fix this. According to configure.in,

case “$target_os” in
solaris*) if test “$GCC” = yes; then
LDSHARED=‘$(CC) -Wl,-G’
if test “$rb_cv_prog_gnu_ld” = yes; then
LDFLAGS=“-Wl,-E”
LDSHARED=“$LDSHARED -shared”
fi
else
LDSHARED=‘ld -G’
fi
rb_cv_dlopen=yes;;
esac

so that if he was using GNU ld, link line should be

gcc -V 3.3 -Wl,-G -shared -L/usr/local/lib

but it wasn’t. It seemed that configure failed to detect GNU ld,
right? Probably we need to fix RUBY_PROG_GNU_LD macro.

Tim, could you show us how did you run configure script?

  					matz.

FWIW, the --with-gnu-ld option fails for me on my Solaris box no matter
what package I use , not just Ruby. I’m guessing it’s a bug in
autoconf. I usually resort to this:

cd /usr/ccs/bin;
mv ld ld.orig;
ln -s /usr/local/bin/ld ld (perhaps backwards - I always forget)

Then build and “mv ld.orig ld” when I’m done.

Anyway, it may be worth giving approach a shot, just to see what happens.

Regards,

Dan

···

In message “Re: Problem compiling extension on Solaris” > on 03/05/27, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

Hmmm, interesting. On my solaris system, I can’t turn of gnu ld.
When compiling ruby I resort to modifying ./configure to say
gnuld = no.

···

On Wednesday, 28 May 2003 at 0:48:22 +0900, Daniel Berger wrote:

Yukihiro Matsumoto wrote:

HI,

In message “Re: Problem compiling extension on Solaris” > > on 03/05/27, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

FWIW, the --with-gnu-ld option fails for me on my Solaris box no matter
what package I use , not just Ruby. I’m guessing it’s a bug in
autoconf. I usually resort to this:

cd /usr/ccs/bin;
mv ld ld.orig;
ln -s /usr/local/bin/ld ld (perhaps backwards - I always forget)

Then build and “mv ld.orig ld” when I’m done.


Jim Freeze

Captain Penny’s Law:
You can fool all of the people some of the time, and some of
the people all of the time, but you Can’t Fool Mom.

Hi,

Would somebody check whether it works or not, if we change

LDFLAGS="-Wl,-E"

to

LDFLAGS="-Wl,-E,-dy"

for Solaris configure.in code. Stephen Gunnell suggested this scheme.

						matz.

BTW, I got the latest from cvs yesterday and ruby built
right out of the box without any special tweeks on solaris.

···

On Wednesday, 28 May 2003 at 0:52:35 +0900, Jim Freeze wrote:

Then build and “mv ld.orig ld” when I’m done.

Hmmm, interesting. On my solaris system, I can’t turn of gnu ld.
When compiling ruby I resort to modifying ./configure to say
gnuld = no.


Jim Freeze

OK, so you’re a Ph.D. Just don’t touch anything.

Moving from C++

Q1.) Is there an equivalent to enumerated types?
Q2.) Is there an equivalent to the const declaration for function parameters? What prevents a function parameter from being
accidently changed?
Q3.) Is this the correct way to handle Hash containers and the objects they hold?

Thanks!

class TransCountHolder
attr_accessor :siteKey, :siteName, :errors, :tranfersCounted, :baudAverage
end

class TransferSummary

const values - enumerated types??? enum {SiteList, TransferErrorCount, BaudRateAverage, TransferErrorCount}

SiteList = 0
TransferErrorCount = 1
BaudRateAverage = 2
TransferCount = 3

def initialize(startDate, endDate, siteKey)
…snip…
@countsContainer = Hash.new
end

def doSummary
# site list
doSql (getSiteListSQL(), SiteList)

  # transfer error count
  doSql (getTransferErrorCountSQL(), TransferErrorCount)
  
  # baud rate average
  doSql (getTransferBaudRateAverageSQL(), BaudRateAverage)
  
  # transfer count
  doSql (getTransferCountSQL(), TransferCount)

end

what prevents whichFunction parameter from being changed???

it would seem the case statement could be replaced by some other language feature???

def doSql(sqlStmt, whichFunction)
database = DatabaseFunctions.new
database.doSql( sqlStmt ) do |dataset|
row.each_with_name do |siteKey, value|
case whichFunction
# SiteList
when SiteList then
transferSummaryCountHolder = TransCountHolder.new(siteKey, value)
@countsContainer[SiteKey] = transferSummaryCountHolder

           # TransferErrorCount                             
           when TransferErrorCount then @countsContainer[siteKey].errors = value  
           
           # BaudRateAverage
           when BaudRateAverage then @countsContainer[siteKey].baudAverage = value    
           
           # TransferCount
           when TransferCount then @countsContainer[siteKey].tranfersCounted = value   
        end                              
     end                                 
  end
  database.finish

end

…various functions snipped…
end

Moving from C++

Q1.) Is there an equivalent to enumerated types?

Not really, but:

BLUE, RED, WHITE = (0..2).to_a

will do similar things.

Q2.) Is there an equivalent to the const declaration for function parameters? What prevents a function parameter from being
accidently changed?

There are not type declarations in Ruby. But you can freeze object, by
calling it's freeze method. Those objects cannot be modified, but it's
up to the called to do this! Another way would be to copy the objects
at the top of the method (using it's dup method).

Regards,

  Michael

···

On Sun, Jun 01, 2003 at 02:00:29AM +0900, Steven Ketcham wrote:

--
ruby -r complex -e 'c,m,w,h=Complex(-0.75,0.136),50,150,100;puts "P6\n#{w} #{h}\n255";(0...h).each{|j|(0...w).each{|i|
n,z=0,Complex(.9*i/w,.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [10+n*15,0,rand*99].pack("C*")}}'|display

Moving from C++

Q1.) Is there an equivalent to enumerated types?
Q2.) Is there an equivalent to the const declaration for function parameters? What prevents a function parameter from being
accidently changed?
Q3.) Is this the correct way to handle Hash containers and the objects they hold?

Thanks!

I found the below on ruby-talk:

Here’s an improved version based on input from David Alan Black and Nat
Pryce:

module Kernel

simple (sequential) enumerated values

def enum(*syms)
n = block_given? ? yield : 0
syms.each_with_index { |s,i| const_set(s,i+n) }
end

enumerated values suitable for bitwise

OR-ing

def set(*syms)
syms.each_with_index { |s,i|
const_set(s,2**i) }
end
end
Thanks,
Jason Voegele

Is this what you are looking for?
BTW, after I became rubyized, I found myself not needing
solutions that were based in C/C++, and for this particular
case, changed my design to use symbols.

···

On Sunday, 1 June 2003 at 2:00:29 +0900, Steven Ketcham wrote:


Jim Freeze

Waste not, get your budget cut next year.

Congratulations!

You’re on the path to easier, more expressive, more readable, and more
maintainable code.

I was so used to doing things the hard way in other languages that
Ruby took a little getting used to.

Enjoy!

···

on 5/31/03 1:00 PM, Steven Ketcham at stedak@charter.net wrote:

Moving from C++


Regards,
JJ

Finally using a Mac!

To clarify, the problem I reported was not that Ruby itself wouldn’t
build on Solaris, it was that I couldn’t build a C extension on
Solaris using Ruby 1.8.0preview2 built with --enable-shared.

I am able to build this extension using Ruby 1.6.8 both with and
without --enable-shared. I will try building it using CVS HEAD this
evening, along with Matz’s suggestion of:

LDFLAGS=“-Wl,-E,-dy”

in configure.in.

···

On Sun, 1 Jun 2003 01:34:19 +0900, Jim Freeze jim@freeze.org wrote:

On Wednesday, 28 May 2003 at 0:52:35 +0900, Jim Freeze wrote:

BTW, I got the latest from cvs yesterday and ruby built
right out of the box without any special tweeks on solaris.

Moving from C++

…snip…

Is this what you are looking for?

Yes, thanks!

BTW, after I became rubyized, I found myself not needing
solutions that were based in C/C++, and for this particular
case, changed my design to use symbols.

Could you elaborate on this a little more?

Thanks!

···

5/31/2003 2:26:03 PM, Jim Freeze jim@freeze.org wrote:

On Sunday, 1 June 2003 at 2:00:29 +0900, Steven Ketcham wrote:


Jim Freeze

Waste not, get your budget cut next year.

I am probably confusing concepts but in C++ you can pass a parameter by reference, pointer or value. Copy constructors,
variable scope and things like that are very important to track. If I pass a complex object by value to a function, the copy
of the object will automatically run it’s destructor when the function
returns. This could be devasting when working with file or database handles.

How are objects handled when passed to a function with Ruby?

Thanks!

Moving from C++

…snip…

···

5/31/2003 1:11:21 PM, Michael Neumann mneumann@ntecs.de wrote:

On Sun, Jun 01, 2003 at 02:00:29AM +0900, Steven Ketcham wrote:

There are not type declarations in Ruby. But you can freeze object, by
calling it’s freeze method. Those objects cannot be modified, but it’s
up to the called to do this! Another way would be to copy the objects
at the top of the method (using it’s dup method).

Regards,

Michael


ruby -r complex -e ‘c,m,w,h=Complex(-0.75,0.136),50,150,100;puts “P6\n#{w} #{h}\n255”;(0…h).each{|j|(0…w).each{|i|
n,z=0,Complex(.9i/w,.9j/h);while n<=m&&(z-c).abs<=2;z=zz+c;n+=1 end;print [10+n15,0,rand99].pack("C")}}’|display

I am both relieved and sorry to say that I cannot reproduce this problem
with either 1.6.8 or CVS HEAD. On Solaris 2.9, I have successfully built
my extension with both versions of Ruby. Both versions were built using
the --enable-shared option. I did not try 1.8.0preview2 again, although
I’ll be glad to if somebody thinks it’s worth doing. In both cases I used
Ruby “out-of-the-box”. I did not change configure.in.

I encountered two minor problems building Ruby from CVS HEAD. Here are a
couple of snippets from make’s output. From the make step I get:

compiling bigdecimal
gcc -V 3.3 -fPIC -O2 -fPIC -I. -I/home/thunter/ruby -I/home/thunter/ruby
-I/home/thunter/ruby/ext/bigdecimal -c bigdecimal.c In file included from
/home/thunter/ruby/ruby.h:21,
from bigdecimal.c:45:
/home/thunter/ruby/config.h:16:1: warning: “_FILE_OFFSET_BITS” redefined
In file included from /usr/include/iso/ctype_iso.h:30,
from /usr/include/ctype.h:18,
from bigdecimal.c:33:
/usr/include/sys/feature_tests.h:96:1: warning: this is the location of
the previous definition

compiling iconv
gcc -V 3.3 -fPIC -O2 -fPIC -I. -I/home/thunter/ruby -I/home/thunter/ruby
-I/home/thunter/ruby/ext/iconv -DHAVE_ICONV_H -c iconv.c iconv.c: In
function iconv_try': iconv.c:154: warning: passing arg 2 of libiconv’ from incompatible
pointer type

compiling readline
gcc -V 3.3 -fPIC -O2 -fPIC -DREADLINE_21_OR_LATER -I. -I/home/thunter/ruby
-I/home/thunter/ruby -I/home/thunter/ruby/ext/readline
-DHAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H -c readline.c In file
included from /home/thunter/ruby/ruby.h:21,
from readline.c:12:
/home/thunter/ruby/config.h:16:1: warning: “_FILE_OFFSET_BITS” redefined
In file included from /usr/include/iso/stdio_iso.h:35,
from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.9/3.3/include/stdio.h:36,
from readline.c:5:
/usr/include/sys/feature_tests.h:96:1: warning: this is the location of
the previous definition

I configured Ruby specifying a non-default prefix. Some of the extensions
still tried to install in the default location. In the interests of
conserving bandwith I’ll only list one:

installing curses
curses.so → /usr/local/lib/ruby/1.8/sparc-solaris2.9/curses.so
/home/thunter/ruby/lib/ftools.rb:23:in initialize': Permission denied - /usr/local/lib/ruby/1.8/sparc-solaris2.9/curses.so (Errno::EACCES) from /home/thunter/ruby/lib/ftools.rb:23:in open’ from
/home/thunter/ruby/lib/ftools.rb:23:in syscopy' from /home/thunter/ruby/lib/ftools.rb:43:in cp’ from
/home/thunter/ruby/lib/ftools.rb:160:in install' from -e:1 *** Error code 1 make: Fatal error: Command failed for target /usr/local/lib/ruby/1.8/sparc-solaris2.9/curses.so’ Current working
directory /home/thunter/ruby/ext/curses

If anybody is interested I can provide the full list.

···

On Mon, 02 Jun 2003 08:43:50 -0400, Tim Hunter wrote:

On Sun, 1 Jun 2003 01:34:19 +0900, Jim Freeze jim@freeze.org wrote:

On Wednesday, 28 May 2003 at 0:52:35 +0900, Jim Freeze wrote:

BTW, I got the latest from cvs yesterday and ruby built right out of the
box without any special tweeks on solaris.

To clarify, the problem I reported was not that Ruby itself wouldn’t
build on Solaris, it was that I couldn’t build a C extension on Solaris
using Ruby 1.8.0preview2 built with --enable-shared.

I am able to build this extension using Ruby 1.6.8 both with and without
–enable-shared. I will try building it using CVS HEAD this evening,
along with Matz’s suggestion of:

LDFLAGS=“-Wl,-E,-dy”

in configure.in.

  • the thing passed is always a reference to an object (even if it’s just
    a number! Numbers are [immutable] objects in Ruby)

  • the object is never destroyed until the mark-and-sweep garbage collector
    finds that it is not being referenced from anywhere. The nearest
    equivalent to a destructor is the “finalizer”, but I have never had a
    use for it myself.

  • although almost everything is an object in Ruby, local variables are
    not: they contain a reference to an object, but you cannot get a
    reference to the variable itself.

    a = Foo.new
    bar(a) # ‘bar’ can modify the object which ‘a’ refers to, but
    # it cannot change ‘a’ to point to a different object [*]

Regards,

Brian.

[*] This is not strictly true, as you can pass a block or proc object
(closure) which binds to a local variable:

def bar
yield “hello”
end

a = 123
puts a.id
bar { |x| a=x }
p a # >> a now points to a String object
puts a.id

But this is cheating - you are not passing a reference to the variable ‘a’
itself, but rather a reference to a piece of code which modifies the
variable ‘a’

···

On Sun, Jun 01, 2003 at 05:45:43AM +0900, Steven Ketcham wrote:

I am probably confusing concepts but in C++ you can pass a parameter by reference, pointer or value. Copy constructors,
variable scope and things like that are very important to track. If I pass a complex object by value to a function, the copy
of the object will automatically run it’s destructor when the function
returns. This could be devasting when working with file or database handles.

How are objects handled when passed to a function with Ruby?

You have a “shoebox” mentally. In other words, you are thinking of
variables as “showboxes” in which you put values. This mental model
works well with C++, where a constructor is run when a shoebox
(variable) is created and a destructor is run when the shoebox is
destroyed. Copy contructors and assigment operators all deal with the
coping of the contents of one shoebox to another.

When dealing with Ruby, forget shoeboxes. Variables are names that are
attached (bound) to values. Names can be rebound at will and multiple
names can be bound to any one object.

See http://www.rubygarden.org/ruby?VariablesAndObjects for a longer rant
on this topic.

···

On Sat, 2003-05-31 at 16:45, Steven Ketcham wrote:

I am probably confusing concepts but in C++ you can pass a parameter by reference, pointer or value. Copy constructors,
variable scope and things like that are very important to track. If I pass a complex object by value to a function, the copy
of the object will automatically run it’s destructor when the function
returns. This could be devasting when working with file or database handles.

How are objects handled when passed to a function with Ruby?


– Jim Weirich jweirich@one.net http://jimweirich.umlcoop.net

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)