Sun Studio Compiler

42 views
Skip to first unread message

Markus

unread,
Jul 13, 2010, 12:57:20 AM7/13/10
to nokogiri-talk
I am trying to compile Nokogiri on Sun Solaris with Sun Studio version
12. It fails due to the hard-coded assumptions about the compiler
Nokogiri makes. CFLAGS is hardcoded to include -Wall and several other
incompatible flags that only work with GCC.

I agree that most people use GCC and I agree that it makes sense to
use those flags IF you are using GCC. What I do NOT agree with is the
fact that these flags are HARDCODED and there seems to be no way to
sensibly override them unless one does a lot of hacking, which I would
rather avoid. If I am wrong on this, please point me to a solution and
I will gladly take it.

$ /opt/ruby/bin/gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.

/opt/ruby/bin/ruby extconf.rb
checking for iconv.h... /opt/ruby/lib/ruby/1.9.1/mkmf.rb:362:in
`try_do': The complier failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:431:in `try_cpp'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:828:in `block in find_header'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:668:in `block in checking_for'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:274:in `block (2 levels) in
postpone'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:248:in `open'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:274:in `block in postpone'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:248:in `open'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:270:in `postpone'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:667:in `checking_for'
from /opt/ruby/lib/ruby/1.9.1/mkmf.rb:827:in `find_header'
from extconf.rb:75:in `<main>'

Gem files will remain installed in /opt/ruby/lib/ruby/gems/1.9.1/gems/
nokogiri-1.4.2 for inspection.
Results logged to /opt/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2/
ext/nokogiri/gem_make.out

Yes, I am able to edit extconf.rb and take out the compiler flags that
don't work and then the C extensions build fine.

After taking out the compiler flags, it looks like this if I run the
commands manually:

$ /opt/ruby/bin/ruby ./extconf.rb
checking for iconv.h... yes
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for gzopen() in -lz... yes
checking for xmlParseDoc() in -lxml2... yes
checking for xsltParseStylesheetDoc() in -lxslt... yes
checking for exsltFuncRegister() in -lexslt... yes
checking for xmlRelaxNGSetParserStructuredErrors()... yes
checking for xmlRelaxNGSetParserStructuredErrors()... yes
checking for xmlRelaxNGSetValidStructuredErrors()... yes
checking for xmlSchemaSetValidStructuredErrors()... yes
checking for xmlSchemaSetParserStructuredErrors()... yes
creating Makefile

The subsequent make command succeeds just as nicely.

[...]
cc -I. -I/opt/ruby/include/ruby-1.9.1/sparc-solaris2.11 -I/opt/ruby/
include/ruby-1.9.1/ruby/backward -I/opt/ruby/include/ruby-1.9.1 -I. -
DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -
DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -
DHAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS -
DHAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS -
DHAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS -I/opt/local/include/libxml2 -
I/usr/local/include/libxml2 -I/opt/ruby/include/libxml2 -I-I-I/opt/
local/include -I-I-I/usr/local/include -I-I-I/opt/ruby/include -I-I-I/
usr/include -I-I-I/usr/include/libxml2 -I-I/opt/local/include -I-I/usr/
local/include -I-I/opt/ruby/include -I-I/usr/include -I-I/usr/include/
libxml2 -I/opt/local/include -I/usr/local/include -I/opt/ruby/include -
I/usr/include -I/usr/include/libxml2 -D_FILE_OFFSET_BITS=64 -KPIC -O
-g -DUSE_INCLUDED_VASPRINTF -O -oxml_element_content.o -c
xml_element_content.c
cc -I. -I/opt/ruby/include/ruby-1.9.1/sparc-solaris2.11 -I/opt/ruby/
include/ruby-1.9.1/ruby/backward -I/opt/ruby/include/ruby-1.9.1 -I. -
DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -
DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -
DHAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS -
DHAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS -
DHAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS -I/opt/local/include/libxml2 -
I/usr/local/include/libxml2 -I/opt/ruby/include/libxml2 -I-I-I/opt/
local/include -I-I-I/usr/local/include -I-I-I/opt/ruby/include -I-I-I/
usr/include -I-I-I/usr/include/libxml2 -I-I/opt/local/include -I-I/usr/
local/include -I-I/opt/ruby/include -I-I/usr/include -I-I/usr/include/
libxml2 -I/opt/local/include -I/usr/local/include -I/opt/ruby/include -
I/usr/include -I/usr/include/libxml2 -D_FILE_OFFSET_BITS=64 -KPIC -O
-g -DUSE_INCLUDED_VASPRINTF -O -oxml_node.o -c xml_node.c
ld -G -o nokogiri.so xml_relax_ng.o xml_sax_parser_context.o
nokogiri.o xml_sax_push_parser.o xml_syntax_error.o
xml_entity_reference.o xml_node_set.o xml_attr.o xml_dtd.o
xml_xpath_context.o xml_namespace.o xml_entity_decl.o xml_comment.o
xml_encoding_handler.o xml_text.o xml_reader.o html_entity_lookup.o
xml_document_fragment.o xml_sax_parser.o xml_cdata.o xslt_stylesheet.o
html_element_description.o xml_processing_instruction.o
xml_attribute_decl.o xml_schema.o html_sax_parser_context.o
html_document.o xml_element_decl.o xml_document.o xml_io.o
xml_element_content.o xml_node.o -L. -L/opt/ruby/lib -L/opt/local/lib -
L/usr/local/lib -L/opt/ruby/lib -L/usr/lib -L. -lexslt -lxslt -
lxml2 -lz -lpthread -lrt -lsocket -ldl -lcrypt -lm -lc

$ ls -l nokogiri.so
-rwxr-xr-x 1 markus markus 970964 Jul 12 21:48 nokogiri.so

However, that still doesn't help me get Nokogiri registered in the
system. So, when I try to install mechanize afterwards (mechanize
being the reason I am trying to install nokogiri in the first place),
it still thinks Nokogiri is missing, goes right back, overwrites my
changes to extconf.rb with the non-working original, and I am stuck
back at square one with a failing build and an aborted install.

Unfortunately, I am not a Ruby or Gems expert, so I haven't found a
feasible way to get any further. Could I solve the problem if I spent
a full day working on it? Probably. I'd rather not, though. There has
to be a better way.

Do you have any suggestions how to work around this? And please don't
say, "use GCC." If I wanted to do that, I would have already.

Thanks,
-Markus

Mike Dalessio

unread,
Jul 13, 2010, 11:02:03 AM7/13/10
to nokogi...@googlegroups.com
Hi.

Unfortunately, we (the maintainers) don't have easy access to Sun CC to make this work for you.

If you can write a patch for the extconf.rb file that works for your compiler, send it to us and we'll apply to master. We recently did something similar for cl.exe, the windows compiler.

1.4.3 is about to be dropped, and we can probably be convinced to include any patches along this line, if you get it to us soon enough. :)
 

Do you have any suggestions how to work around this? And please don't
say, "use GCC." If I wanted to do that, I would have already.

We would never do that! We are pragmatic people. ;)

Thanks for using Nokogiri.

-m

Markus

unread,
Jul 13, 2010, 11:50:50 PM7/13/10
to nokogiri-talk
Hi Mike,

Thanks for your reply.

> If you can write a patch for the extconf.rb file that works for your
> compiler, send it to us and we'll apply to master. We recently did something
> similar for cl.exe, the windows compiler.

I created this diff. It may not be the most elegant solution and it's
not ideal in the sense that it seems to be ignoring the $CC
environment variable when it actually comes to invoking the compiler
later (it'll still call "cc", even if I "export CC=gcc"). That part
seems out of the scope of this script, though. It may pick the
compiler based on which compiler was used to build Ruby itself. Not
sure. -- It does properly pick the compiler flags based on $CC with my
patch, though.

If the command "$CC -v" contains the string "gcc", it'll append the
GCC specific CFLAGS. Otherwise, it won't.

With cc = Sun Studio:

$ grep ^CFLAGS Makefile
CFLAGS = -KPIC -O -g -DUSE_INCLUDED_VASPRINTF

With cc sym-linked to gcc:

$ grep ^CFLAGS Makefile
CFLAGS = -KPIC -O -g -DUSE_INCLUDED_VASPRINTF -O3 -Wall -Wcast-
qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline

Note that -KPIC is not working for GCC, but that, too, seems to be
coming from the compiled-in Ruby defaults. Nothing that can be done
about it in extconf.rb, I think.

------------------------------------------------------------------------------------------------------------
$ cat cflags.diff
diff --git a/ext/nokogiri/extconf.rb b/ext/nokogiri/extconf.rb
index ce6276a..7584a35 100644
--- a/ext/nokogiri/extconf.rb
+++ b/ext/nokogiri/extconf.rb
@@ -42,7 +42,11 @@ if Config::CONFIG['target_os'] =~ /mswin32/
else
lib_prefix = ''

- $CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -
Wmissing-noreturn -Winline"
+ mycc=`#{RbConfig::MAKEFILE_CONFIG['CC']} -v 2>&1`
+ if mycc =~ /gcc/ then
+ $CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion
"+
+ "-Wmissing-noreturn -Winline"
+ end

HEADER_DIRS = [
# First search /opt/local for macports
------------------------------------------------------------------------------------------------------------

Let's put it this way. It should work as long as folks use the same
compiler to compile their native extensions that they used to compile
Ruby with. I guess most people will. It should take care of the hard-
coded compiler flags and compiler name that don't come from
extconf.rb.

Regards,
-Markus

Mike Dalessio

unread,
Jul 16, 2010, 10:55:51 AM7/16/10
to nokogi...@googlegroups.com
Hi Markus,

On Tue, Jul 13, 2010 at 12:57 AM, Markus <mma...@gmail.com> wrote:
I am trying to compile Nokogiri on Sun Solaris with Sun Studio version
12. It fails due to the hard-coded assumptions about the compiler
Nokogiri makes. CFLAGS is hardcoded to include -Wall and several other
incompatible flags that only work with GCC.

This has been fixed in master! It should be in the 1.4.3 release that @tenderlove's going to drop Real Soon Now™. :)


-m
 

Markus

unread,
Jul 18, 2010, 12:11:07 AM7/18/10
to nokogiri-talk
Hi Mike,

Thanks. This is muchly appreciated.

-Markus
Reply all
Reply to author
Forward
0 new messages