Showing posts with label cc. Show all posts
Showing posts with label cc. Show all posts

Monday, May 07, 2007

Installing MySQL on Solaris 10 Virtual Machine: gcc and cc Compiler Option Differences

I left the last post in this series at the point of running make for the bitkeeper client. If you have been following the posts and tried to do that, you will be greeted with the following errors:
bash-3.00# make
cc -O2 -Wall -Wno-parentheses bkf.c -o bkf
cc: Warning: option -2 passed to ld
cc: illegal option -Wall
make: *** [bkf] Error 1

The first line shows the compiler options being used followed by a warning and an error. The reason we are getting this error is because cc options != gcc options. We have two solutions at hand at this point:

1. Use gcc (we installed it earlier)
2. Change the compiler options to use cc's compiler options instead of gcc.

Using gcc compiler
To use the gcc compiler instead of cc, do the following:
bash-3.00# CC=`which gcc`
bash-3.00# export CC
bash-3.00# make

This will let you go past the first set of errors. make will now be stopping with the following errors.
bash-3.00# make
/usr/local/bin/gcc -O2 -Wall -Wno-parentheses bkf.c -o bkf
Undefined first referenced
symbol in file
gethostbyname /var/tmp//ccGSplTt.o
socket /var/tmp//ccGSplTt.o
connect /var/tmp//ccGSplTt.o
ld: fatal: Symbol referencing errors. No output written to bkf
collect2: ld returned 1 exit status
make: *** [bkf] Error 1

These errors mean that you need to set LDFLAGS as follows
export LDFLAGS="-lsocket -lnsl -lm"

Now running make should produce no errors.
bash-3.00# make
/usr/local/bin/gcc -O2 -Wall -Wno-parentheses -lsocket -lnsl -lm bkf.c -o bkf

Using the cc compiler flags
To change the gcc compiler flags to cc compiler flags, edit the Makefile and replace the line that specifies the gcc options with a line using options recognized by cc. So, you would find the line:
CFLAGS=-O2 -Wall -Wno-parentheses

and replace with
CFLAGS=-xO2 -v

Regarding -Wno-parentheses, James Carlson of Sun Microsystems pointed out the following:
Gcc does have it documented in the 'info' files; you just have to look
under "-Wparenthesis" in the warning options.

For the equivalent outside of gcc, see lint's "-errchk=no%parenthesis"

option. (Our tool chain doesn't get lint and cc confused. ;-})

Now running make will produce
bash-3.00# make
cc -xO2 -v bkf.c -o bkf
"bkf.c", line 196: warning: Function has no return statement : clone
Undefined first referenced
symbol in file
gethostbyname bkf.o
socket bkf.o
connect bkf.o
ld: fatal: Symbol referencing errors. No output written to bkf
make: *** [bkf] Error 1

To get rid of the undefined symbols, you would need to link the right libraries.

Al Hopper of Logical Approach Inc, once gave me a very handy tip to find more about the "mysterious" undefined symbol. He suggested using something like (run for both /lib and /usr/lib):
for i in /lib/*.so
do
/usr/ccs/bin/nm -Ag $i |grep -v UNDEF |grep gethostbyname
done


which produces:
/lib/libnsl.so: [2643]  |    110640|      89|FUNC |GLOB |0    |11     |gethostbyname
/lib/libnsl.so: [2683] | 110202| 222|FUNC |GLOB |0 |11 |gethostbyname_r
/lib/libnsl.so: [3113] | 128448| 174|FUNC |GLOB |0 |11 |_switch_gethostbyname_r
/lib/libnsl.so: [2841] | 110108| 44|FUNC |GLOB |0 |11 |_uncached_gethostbyname_r
/lib/libresolv.so: [1585] | 78996| 38|FUNC |GLOB |0 |11 |res_gethostbyname
/lib/libresolv.so: [1397] | 79034| 41|FUNC |GLOB |0 |11 |res_gethostbyname2
/lib/libxnet.so: [79] | 0| 0|FUNC |GLOB |0 |ABS |gethostbyname

This will tell us that we need the "-lnsl". Similarly running a slightly modified version of the above, we can find out that we also need "-lsocket" specified in LDFLAGS.

The approach I mention above is a bit controversial so use it only if you know the issues it could drag you into. There are other ways to get the same information such as "man socket" and "man gethostbyname" that will do the job in most cases.

export LDFLAGS="-lsocket -lnsl -lm"

At this point, you should be able to run make without any issues.
bash-3.00# make
cc -lsocket -lnsl -lm bkf.o -o bkf


to be continued.

Saturday, May 05, 2007

Installing MySQL on Solaris 10 Virtual Machine

Now that I am happy with my Solaris 10 virtual machine running on my Mac Book, I can proceed with installing (compiling) MySQL on it. However as you can expect, the default Solaris 10 installation doesn't install cc compiler by default. We can confirm that if the following error message is displayed when running we run cc on Solaris 10 console:
bash-3.00# cc
/usr/ucb/cc: language optional software package not installed

What this means is that we need to install Sun Studio 11 from Sun site. Before downloading you need to be logged in. The download file studio11-sol-x86.tar.bz2 is about 332.6MB.

Once you have it installed, check the checksum and then proceed with decompressing the Sun Studio 11 bz2 file. Note I used the very verbose and keep option. You may or may not want to use them.
bzip2 -d -v -v -k studio11-sol-x86.tar.bz2
time tar -xvf studio11-sol-x86.tar > studio11-install.log
# 4m53s


Among other files, it will put an InstallGuide_Solaris.pdf file which you should read before installing. On Solaris you can use gpdf to launch the file.

One thing to note when installing Sun Studio 11 is that you will need to set your PATH environment variable. By default the PATH variable will be set as following:
echo $PATH
/usr/sbin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/ucb

Since Sun Studio 11 will be installed in /opt/SUNWspro/bin we will need to add this to the PATH variable. To set the PATH variable, put the following line in your ~/.bashrc
export PATH=$PATH:/opt/SUNWspro/bin

Once the above has been placed, you will need to "dot" the file.
. ~/.bashrc

Now your PATH should be setup appropriately. Similarly you will need to setup MANPATH to include /opt/SUNWspro/man.

Once the Sun Studio will be installed, we will be able to access the documentation from /opt/SUNWspro/docs/index.html.

Before continuing, we should have ample swap space defined. You can add swap space by following the procedure below. On your Solaris 10 virtual machine, make sure you don't create the new swap file at / or you may get an error relating to no more space left on device. Since I created the virtual file system at /export/home through Parallels, I have prefixed my swap file location with /export/home.
mkdir /export/home/swap
mkfile 2048m /export/home/swap/2gswap
ls -l /export/home/swap/2gswap

When I tried to specify the new swap space, I got the following error. This is related to me setting a small swap size using Parallels. To correct this, I will need to set swap space higher through Parallels and then try again.

swap -a /export/home/swap/2gswap
# size is invalid


I tried again with 900M swap and it worked fine.

Now we can either run the installer in GUI or command-line mode. I haven't yet used the GUI installer to install Sun Studio 11 so I am going to do that just out of curiosity.

To launch the GUI installer, navigate to where you decompressed the Sunstudio11 files and run
./installer

To launch in command line mode:
./installer -nodisplay


Once the installer launches, click next to go to and accept the agreement. On the next screen make sure only English is selected. Keep the default selections selected for installation.

For the Sun Studio 11 software install directory, make sure it is /opt or you may need to modify your PATH and MANPATH variables accordingly.

Next you can review the installation and once you confirm the installation will begin.

Once the installation is complete, you will be able to see the log files created during install at
cd /var/sadm/install/logs


Some interesting information is available in /opt/SUNWspro/READMEs/email_template.txt.

At this point you should be able to run the IDE by executing
sunstudio
.

You should check to make sure that which cc doesn't return /usr/ucb/cc. If it does then do the following:
cd /usr/ucb
rm cc
ln -s /opt/SUNWspro/bin/cc cc

I will continue in the next post.