Recent Changes - Search:

Help Topics

User Accounts

Network Access

Other/Outdated Documentation

Additional Help

Staff Docs

  • (Private)

edit SideBar

FAQ /

Development


1.  Solaris

This section explains how to use Solaris compilers and libraries to compile your code.

1.1  Compilers

The following are the C/C++ compilers available:

  • Sun's SunStudio cc/CC in /opt/SUNWspro/bin
  • GNU gcc/g++ in /usr/local/gnu/bin
  • /usr/ucb/cc is evil and should never be used.

Both cc and gcc compile ANSI code as well as K&R style C.

Other Sun compilers/compiler tools, including Fortran f77,f90,f95 compilers are available under /opt/SUNWspro/bin/.

Man pages are in /opt/SUNWspro/man for Sun's tools and in /usr/local/gnu/man for GNU tools.

The Sun Studio suite is a robust group of compilers and and IDE (sunstudio) that generates very good 32bit and 64bit code for Solaris on both Ultrasparc processors and x86/amd64 processors.

1.2  Libraries and LD_LIBRARY_PATH

One of the more confusing things when compiling code is telling the compiler where libraries are so it can link the code and create an executable binary.

  • The -l option tells the compiler to link in the library that follows it. If some call needs extra libraries it is usually mentioned in the man page for it. For example, when programming sockets -lsocket and -lnsl will need to be added to the cc/gcc link line. Another common library is the math library, which requires an -lm.
  • The -L option takes a directory to look in for libraries that are not in /usr/lib. For example when compiling X11 code either -L/usr/openwin/lib or -L/usr/local/X/lib will need to be added to the final cc/gcc link line.
  • The -R option is similar to the -L option and should always be used when the -L option is used. This places the runtime location of the library into the binary. Usually the -L and -R options will take the same directories, but that is not a requirement. This option should always be used when -L is used so LD_LIBRARY_PATH does not need to be set. Many Makefiles leave off the -R option, but have a variable where it could be added easily. Wherever you see a -Lwhatever, just add a -Rwhatever to that variable. LD_RUN_PATH can also be used at compile time instead of -R to do the same thing.
  • LD_LIBRARY_PATH This environment variable consists of a colon separated list of directories to look in for libraries. It is best to not have it set. Problems with this variable are:
    • Causes things not to work, as programs can pick up libraries they weren't meant to use. For example programs getting different X11 libraries than they were compiled for. This often causes things such as xfig in SunOS not to work, among other programs. Also can cause very serious problems in Solaris if a /usr/ucblib library is found, for example, compiling a curses program is impossible if /usr/ucblib is in it.
    • Slows the execution of every program you run down, as every directory listed will be searched. The longer LD_LIBRARY_PATH is the slower things will be.
    • Can cause the compiling of some programs to be impossible.
    • Not necessary when program is compiled correctly with -R

The only case that this should be used is with a program available in binary form only, in which case a wrapper script, be sure to make it executable, should be written around it like this:

#!/bin/sh 
LD_LIBRARY_PATH=/path/to/lib 
export LD_LIBRARY_PATH 
exec Binary_prog_real $*

or one can also use (with tcsh or csh):

env LD_LIBRARY_PATH=/path/to/lib Binary_prog

Replace Binary_prog with the name of the program.

  • Bottom line: avoid LD_LIBRARY_PATH at all costs.
  • Makefiles usually have variables to change/add -L and -R
  • The BSD compatibility libraries are considered broken and should not be used

1.3  Header files

Associated with finding the right libraries, one must first find the right header files. Most calls will list what header files they need in their man page. There are two sets of X11 headers and libraries. Those standard with Solaris are under /usr/openwin and those that we compiled locally are in /usr/local/X. To use the local X11 libraries -I/usr/local/X/include will have to be added to each cc/gcc line. Motif libraries require -I/usr/dt/include and then -L/usr/dt/lib and -R/usr/dt/lib on the link line. Also see previous answer on libraries.

1.4  Other compiling tools

  • make
    Is located in /usr/ccs/bin/.
    GNU version in /usr/local/gnu/bin/.
  • cpp -- the C preprocessor
    Is located in /usr/ccs/lib/.
  • dbx -- the debugger
    Is located in /opt/SUNWspro/bin/.
    GNU version is /usr/local/gnu/bin/gdb.
    Also an X interface to GDB is /usr/local/X/bin/xxgdb.
  • lex
    Is located in /usr/ccs/bin/.
    GNU version is /usr/local/gnu/bin/flex.
  • yacc
    Is located in /usr/ccs/bin/.
    GNU version is /usr/local/gnu/bin/bison.
  • lint
    Is located in /opt/SUNWspro/bin/.
  • as
    Is located in /usr/ccs/bin/.
  • ldd
    Is in /usr/bin. It shows what dynamic libraries a program will use.
  • truss
    Is in /usr/bin and is very useful for debugging system calls.
  • dis
    Is in /usr/ccs/bin and is an object code disassembler.
  • ld
    Is in /usr/ccs/bin and is the link editor for object files.
  • ar
    Is in /usr/ccs/bin makes archives, .a library files, out of .o files GNU version is /usr/local/gnu/bin/gar.

Sun tools are kept up to date. An attempt is also made to keep GNU tools as up to date as possible.

Man pages for GNU tools are in /usr/local/gnu/man/.

1.5  Sun Studio IDE

To run the Sun Studio IDE just run sunstudio. A screenshot of it starting up is .

1.6  64 bit vs. 32 bit compiling

Solaris has supported 64bit execution of programs on Ultrasparc since Solaris 7. By default the compilers will produce 32bit binaries.

To produce a 64bit binary with Sun's compilers on Ultrasparcs add the -xarch=v9 option to cc or CC. For AMD64 processors add -xarch=amd64 instead on Solaris x86. NOTE: With Sun Studio 12 the -xarch option is deprecated. To compile 64 bit code use -m64 (this matches the gcc option.

To produce a 64bit binary with GNU compilers add the -m64 option to gcc or g++ on either architecture. Expect that the code produced with the Sun compilers to be better, especially in the case of compiling for 64bit.

64 bit executables have the advantage of having a much larger address space. If you do not need 64 bit features on Ultrasparc you are better off using 32 bit binaries on Ultrasparc as pointers take up twice as much space and some programs may run slower as a result. However for the AMD Opteron (amd64) expect a 64bit binary to run about 20% faster than a 32bit binary. This speed up is caused by the Opteron having twice as many integer registers available in 64bit mode. Of course, different programs may experience different results. On a Xeon with 64bit extensions no speedup has been observed.

Use the 'isainfo -b' command to see if the host is running a 32bit or 64bit kernel. If it's running a 64bit kernel, then it can run 64bit binaries. See the man pages for isainfo and isaexec for more info.

1.7  Compiling example

Here is an example of using -l, -I, -L and -R to compile a 32bith program that uses OpenSSL.

cc -I/usr/local/openssl/include -o program program.o -L/usr/local/openssl/lib -R/usr/local/openssl/lib -lcrypto -lssl

To compile a 64bit binary on an Ultrasparc do this:

cc -xarch=v9 -I/usr/local/openssl/include -o program program.o -L/usr/local/openssl/lib/sparcv9 -R/usr/local/openssl/lib/sparcv9 -lcrypto -lssl

And to compile a 64bit binary for an AMD64 processor:

cc -xarch=amd64 -I/usr/local/openssl/include -o program program.o -L/usr/local/openssl/lib/amd64 -R/usr/local/openssl/lib/amd64 -lcrypto -lssl

Notice the different paths to find the 64 bit libraries.

2.  Linux

This section offers a brief summary of development tools in the ECE/CIS GNU/Linux distribution.

2.1  Compilers

The following are the C/C++ compilers available

  • GNU gcc/g++ in /usr/local/gcc/bin

2.2  IDEs

A number of common Linux IDEs have been installed and are available for your projects:

  • Sun Studio (sunstudio)
  • Eclipse SDK (eclipse)
  • Kdevelop (kdevelop)

2.3  Libraries and Header files

Similar to Solaris -I, -L and -l are used to find header files and libraries.

2.4  64 bit vs. 32 bit compiling

Most Linux systems are 32bit only, however mlb is running 64bit Linux. By default gcc/g++ will produce 64bit executables on mlb. The Opteron processor will execute 64bit programs about 20% faster than 32bit programs due to twice as many integer registers being available. If you have problems with your program running or linking, try compiling a 32bit binary by using gcc -m32.


Comments

To add a comment, click the link below. You are free to contribute anonymously, but it is preferred that you sign your comments with your name. Simply add ~~~~ to the end of your comment to sign it. Regardless of whether you sign your comment, your username will be visible on the History page.
(Add Your Own)


Edit - History - Print - Recent Changes - Search
Page last modified on June 20, 2007, at 08:21 AM