# Problem compiling extension on Solaris

**URL:** <https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126>\
**Category:** ruby-talk\
**Created:** [25 May 2003 21:16 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126 "2003-05-25T21:16:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)\
**Post date:** [25 May 2003 21:16 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/1 "2003-05-25T21:16:01Z")

</div>

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](http://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](http://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](http://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.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [26 May 2003 08:25 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/2 "2003-05-26T08:25:48Z")

</div>

Hi,

> **···**
>
> In message “Problem compiling extension on Solaris” on 03/05/26, “Tim Hunter” [cyclists@nc.rr.com](mailto: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.
> 
> ```

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)\
**Post date:** [26 May 2003 12:39 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/3 "2003-05-26T12:39:23Z")

</div>

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

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](mailto: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.
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [26 May 2003 18:46 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/4 "2003-05-26T18:46:25Z")

</div>

Hi,

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

:-\<

> 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](mailto:cyclists@nc.rr.com) writes:

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [26 May 2003 22:47 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/5 "2003-05-26T22:47:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [27 May 2003 05:30 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/6 "2003-05-27T05:30:53Z")

</div>

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](mailto:nobu.nokada@softhome.net) [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) writes:

---

<div class="post-metadata">

**Author:** ![Berger\_Daniel2](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@Berger\_Daniel2](https://rubytalk.org/u/Berger_Daniel2)\
**Post date:** [27 May 2003 15:48 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/7 "2003-05-27T15:48:22Z")

</div>

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](mailto:nobu.nokada@softhome.net) [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) writes:

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [27 May 2003 15:52 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/8 "2003-05-27T15:52:35Z")

</div>

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](mailto:nobu.nokada@softhome.net) [nobu.nokada@softhome.net](mailto: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.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [31 May 2003 05:10 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/9 "2003-05-31T05:10:01Z")

</div>

Hi,

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

LDFLAGS="-Wl,-E"

to

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

for Solaris [configure.in](http://configure.in) code. Stephen Gunnell suggested this scheme.

```
						matz.
```

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [31 May 2003 16:34 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/10 "2003-05-31T16:34:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steven\_Ketcham](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@Steven\_Ketcham](https://rubytalk.org/u/Steven_Ketcham)\
**Post date:** [31 May 2003 17:00 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/11 "2003-05-31T17:00:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![George5](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@George5](https://rubytalk.org/u/George5)\
**Post date:** [31 May 2003 17:11 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/12 "2003-05-31T17:11:31Z")

</div>

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

&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [31 May 2003 18:26 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/13 "2003-05-31T18:26:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Johnson](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@John\_Johnson](https://rubytalk.org/u/John_Johnson)\
**Post date:** [1 June 2003 00:50 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/14 "2003-06-01T00:50:48Z")

</div>

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](mailto:stedak@charter.net) wrote:
> 
> > Moving from C++
> 
> –  
> Regards,  
> JJ
> 
> Finally using a Mac!

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter3](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@Tim\_Hunter3](https://rubytalk.org/u/Tim_Hunter3)\
**Post date:** [2 June 2003 14:06 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/15 "2003-06-02T14:06:21Z")

</div>

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](mailto: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.

---

<div class="post-metadata">

**Author:** ![Steven\_Ketcham](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@Steven\_Ketcham](https://rubytalk.org/u/Steven_Ketcham)\
**Post date:** [31 May 2003 20:12 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/16 "2003-05-31T20:12:27Z")

</div>

> > 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](mailto: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.

---

<div class="post-metadata">

**Author:** ![Steven\_Ketcham](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@Steven\_Ketcham](https://rubytalk.org/u/Steven_Ketcham)\
**Post date:** [31 May 2003 20:45 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/17 "2003-05-31T20:45:43Z")

</div>

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](mailto: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(.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

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)\
**Post date:** [4 June 2003 00:34 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/18 "2003-06-04T00:34:15Z")

</div>

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](mailto: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.

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [31 May 2003 21:04 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/19 "2003-05-31T21:04:54Z")

</div>

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

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?

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich2](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@Jim\_Weirich2](https://rubytalk.org/u/Jim_Weirich2)\
**Post date:** [31 May 2003 21:36 UTC](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126/20 "2003-05-31T21:36:53Z")

</div>

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](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](mailto:jweirich@one.net)[http://jimweirich.umlcoop.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)

[Next page](https://rubytalk.org/t/problem-compiling-extension-on-solaris/6126.md?page=2)
