Informatics

Compiling complex numbers in C on a Solaris 9 platform

In a previous post I introduced “circle, an app for analysing byte statistics in files in a visual way.

Being a very small C99 project, I tried to compile it in an old Solaris 9 platform (SPARC processor), and noticed that I couldn’t find <complex.h> anywhere in the machine.

The only clue I’ve found about Solaris and complex numbers with C99 which btw, must (should?) be supported, is that they should be supported in Solaris 10 though the code isn’t as easy as in the C99 usual case.

circle uses complex numbers internally for representing the circle of bytes so <complex.h> is a must when compiling… Nonetheless, it seems that Solaris 9 doesn’t have any support for complex numbers:

I tried the native cc compiler, but as there’s no complex.h anywhere, it is of no use. The C++ compiler indeed has a complex.h header but it is not usable for the C case.

Then I tried to use the OpenCSW project —the only site in internet that actually provides a free package manager for (almost) updated packages, as Sunfreeware now offers its services via subscription (though for corporations it is a very good option). I installed a more modern C compiler (gcc), still without lucky, as no complex.h is still available.

:-o

I finally tried to quickly fix it: I only needed basic complex numbers support, so probably some basic header with the definitions from any project could do the job… And in fact I found a neat sample of code related to the MinGW project, so I used it: downloaded both complex.h and _mingw.h, and after some tweaking to make these two files to glue the rest of the project (changing some include <> to include “”, and commenting out “#include <sdkddkver.h>” in _mingw.h as it is not needed for our particular very reduced needs)… the project compiled!

# /opt/csw/gcc3/bin/gcc -std=c99 -lm circle.c statistics.c -o circle -O2

Here we can see that it has been compiled against the native Solaris C math library (libm.so.1):

# ldd circle
libm.so.1 =>     /usr/lib/libm.so.1
libc.so.1 =>     /usr/lib/libc.so.1
libdl.so.1 =>    /usr/lib/libdl.so.1
/usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1

The compiled circle for Solaris 9 can be found here.

I didn’t try the native cc or older gcc’s, as _mingw.h has a warning against using GCC<3.4.5, and I didn’t want to comment it bearing in mind that I had a handy gcc:

# cc -std=c99 -lm circle.c statistics.c
In file included from complex.h:28,
from statistics_circle.h:27,
from circle.c:11:
_mingw.h:55:2: #error ERROR: You must use a GNU Compiler version >= 3.4.5.

As a final note, I think  that probably Solaris 9 is not C99 compliant (even with gcc)…:

The Oracle Solaris 10 OS includes two versions of libm: libm.so.1 and libm.so.2.

libm.so.1 provides the functions required by those standards supported by the Oracle Solaris 9 OS and earlier versions.

libm.so.2 provides the functions required by those standards supported by the Oracle Solaris 10 OS (including C99).

Even more intriguing are some patches for Solaris 9, like “111721-04“, which says in the README:

Problem Description:
4820770 ANSI C++ <cmath> support lacks float and long double signatures

(how on earth could that happen!?)

I’m still puzzled about Solaris 9 missing complex numbers in C. But as it is a discontinued OS with some strange patches (like the previous one) and tricky investigations related to libm.so, and with problems with complex numbers even in Solaris 10, I’ve given up trying to find the deep reason or a better patch. This page though may have the key:

…The fundamental problem […] was built on a Solaris 9 release with the C99 patches installed. These patches are not publicly available, and many Solaris 9 systems don’t have them.

Well… that’s funny… I mean, the C99 standard was adopted as ANSI standard on 2000, and Solaris 9 was not released until May 2002… so, why all the patches them?

2000 << 2002

:-(

To relax frustrations I can’t help but to circle the Solaris executable itself:

$ circle circle.SOLARIS_9_SPARC

circle-solaris-version-self-referencedNote that it completely lacks 12 byte values!

2 thoughts on “Compiling complex numbers in C on a Solaris 9 platform

  1. thank you! this helped me compiled stress-ng for solaris 8 which also uses complex numbers. not that i need it for physical hardware – just want to stress test the qemu sparc support to ensure it can replace our old stuff!

Leave a reply to circulosmeos Cancel reply