PDA

View Full Version : Howto: Installing a C/ C++/ Perl program, library, or module


Matt
11-09-2001, 01:19 PM
How to install a C, C++, or Perl program, library, or module from source
Keywords: perl module , c c++ library , install from source , local install , pgcc
Introduction: At some point you may wish to install a piece of software to your local account. Whether this is a Perl module that FutureQuest does not support or a C library, this FAQ should provide valuable information.
Notation: In this tutorial, I use the color blue to designate a command to be typed at the command line. You will need to login via telnet or SSH in order to enter these commands. xdomain represents your domain and you should substitute xdomain with your appropriate account name. I also haven't spelled out when to hit <Enter>. This should be fairly obvious (the end of a command or a newline).

Before Starting
If you are attempting to install a Perl module, the first thing to do is make sure that it isn’t already installed (e.g perl -MDate::Calc -e '{1}') If it isn’t installed and is available via CPAN (http://www.cpan.org), you may request that FutureQuest install it for you. If FutureQuest will not install the module as root, there is likely a good reason. It may require a vast amount of server resources, be outdated or incompatible, buggy, or simply in very low demand. If it is the case that the module is in low demand or outdated, go ahead. But if it requires vast resources or is incompatible, it will not work (best case scenario) or incur the wrath of Terra (worst case scenario). Although there are restrictions placed on running modules and programs that are meant to keep them from overwhelming the server, it is still a good idea to ask about a particular module or program before you install it.

Do I install from source or just upload the binary?
If possible, you should install from source. If you are installing a library or Perl module, you must install from source. If you are trying to install a program, it might be simpler to upload the binary (not necessarily better). However, there are advantages to installing from source, namely that the compiled program will be optimized for the hardware it is being run on (potentially running faster and consuming less resources). If the program dependencies are such that they cannot be met, uploading the binary may be your last hope. Keep in mind, that you will need the binary for Linux ELF- Intel x86 machines... not an RPM file. It may also be handy to know that the servers are running Red Hat Linux.

Obtaining the source code:
The first step to installing the software is to obtain the source code. You should always try to locate the most current code and download it from a reputable source, such as the author’s site or a central repository like CPAN (http://www.cpan.org). If the code is available in several different compression formats, I prefer to download it as a .tar.gz file (.tar and .bz are UNIX compression formats; .zip is a Windows compression format).

Setting up my FutureQuest account to install new software:
You should create the following directories (if they don’t already exist) in your account (using either FTP software or 'mkdir' at the command line):
/big/dom/xdomain/tmp
/big/dom/xdomain/bin
/big/dom/xdomain/lib
/big/dom/xdomain/include
/big/dom/xdomain/man
/big/dom/xdomain/usr
This directory structure should help alleviate some potential error codes when compiling certain pieces of software

Getting the source code from my computer to the FutureQuest servers:
Use FTP (binary mode) to upload the compressed source code file that you obtained to your tmp directory. The next step is to decompress the software. Login via telnet or SSH to your account and cd to the tmp directory. If the file is of the format *.tar.gz, you can decompress it in one step by typing gzip -dc filename.tar.gz | tar xvf - at the command line. If it ends in some other format, the Aota tutorials are a good starting point for learning how to decompress them. If the information isn’t there, do an Internet search for it.

Compiling and Installation:
cd to the newly created directory. This directory typically contains a makefile that may be named Makefile (C/ C++) or Makefile.PL (Perl). If it does not, you may have to cd into a subdirectory such as 'source'. Once you are in the directory containing the makefile, follow these steps for a Perl makefile:
perl Makefile.PL
make
make test
make install
For C/ C++ the commands to type are:
make all
make install

If you don’t get any errors, congratulations and consider yourself lucky. For everyone else, proceed to the Troubleshooting section.

Troubleshooting:
Q. I attempt to compile the program using 'make' but get an error stating that I do not have write permission.
A. In this case, the makefile assumes that it has access to a directory to which you do not have proper permissions (most likely root). You must explicitly define the local installation directory. The first thing I do is start fresh, by deleting the current working directory (e.g. rm –R somedir) and then decompressing the source code again. So repeat everything you just did up until you get to the Compiling and Installation step.
Now, if you are dealing with a Perl makefile (Makefile.PL), type the following:
perl Makefile.PL PREFIX=/big/dom/xdomain
make
make test
make install

For C/ C++ the commands to type are:
./configure --prefix=/big/dom/xdomain
make all
make install

If you don’t get any errors, congratulations. If you are unlucky enough to get additional errors, read on.

Q. After running 'make', I get an error message mentioning 'pgcc.' What do I do now?
A. This is addressed in the following post: http://www.aota.net/ubb/Forum3/HTML/000742-1.html
The solution, in summary, is to create a script to turn the pgcc compiler on or off (off by default). The script is shown below. To turn the pgcc compiler on once you have created the script, simply type tpgcc on. To turn it off, type tpgcc off. To query whether it is currently on or off, type tpgcc. Turn the pgcc compiler on and run make again.

“Just install the following function into your ~/.bashrc file...”

tpgcc ()
{
case $1 in
on ) if [ "$CFLAGS" ]; then
echo "pgcc is already default compiler"
exit
else
PATH=/opt/pgcc/bin:$PATH
CC=pgcc
CFLAGS="-O3 -mpentiumpro -march=pentiumpro"
export PATH CC CFLAGS
echo "pgcc is now the primary compiler"
fi
;;
off ) if [ -z "$CFLAGS" ]; then
echo "pgcc is already turned off"
else
PATH=${PATH#/opt/pgcc/bin:}
unset CFLAGS
unset CC
export PATH CC CFLAGS
echo "pgcc is now turned off"
fi
;;
* ) if [ "$CFLAGS" ]; then
echo "pgcc status: on"
else
echo "pgcc status: off"
fi
;;
esac
}
export -f tpgcc


Accessing local libraries/ modules:
Once you have installed a library or module, the script or program that requires it still may not run. It will be necessary to point the program or script to the local directory. In a Perl script, you should add the following line above all other code, but under the #!/usr/bin/perl line: use lib ‘pathtolib’ where pathtolib is the explicit path to your newly installed library. Some examples of what this line might look like include:
use lib '/big/dom/xdomain/lib/perl5/site_perl/5.005/i686-linux/';
use lib '/big/dom/xdomain/perllib';

If the script/ program still complains about not being able to find the library, the pathtolib string that you are using is incorrect. If you want to try several at once, you can, but put each possibility on a separate line:
use lib 'pathtolib1';
use lib 'pathtolib2’;
use lib ' pathtolib3';
use lib ' pathtolib4';
If this works, you can then go back and comment each line out until the script breaks again. The line you just commented out contains the proper pathtolib. Uncomment this line and delete the rest.

This should solve many of your problems. I have never encountered a C/ C++ library that is set up independent of other software... so you should rarely, if ever, need to specify where a local C/C++ library has been installed. If you do, there is likely to be a corresponding command to the Perl use lib (#include comes to mind).

Miscellaneous
Q. How do I distinguish executables from non-executables?
A. Executable programs are indicated by the presence of an asterisk (*) after the filename

Q. I compiled a program and it is seen as executable. How do I run it from the command line?
A. Just type ./program where program is the name of the executable.

Well, this is it. If I've made any errors, plese let me know and I will correct them. Hope others find this helpful. -Matt

Slim
11-11-2001, 09:39 AM
How timely can you get?

I'm considering use of the perl HTTPD modules. What's the right way to request FutureQuest to install them, or to determine that they are safe to install locally? I don't mind installing them locally, and it is indeed possible that I will only use them for a while, until I determine my ultimate method to get the job done.

Terra
11-11-2001, 10:02 AM
Matt:

Excellent writeup - thanks!!!

Setting up my FutureQuest account to install new software:
You should create the following directories (if they don’t already exist) in your account (using either FTP software or 'mkdir' at the command line):
/big/dom/xdomain/tmp
/big/dom/xdomain/bin
/big/dom/xdomain/lib
/big/dom/xdomain/include
/big/dom/xdomain/man
/big/dom/xdomain/usr
This directory structure should help alleviate some potential error codes when compiling certain pieces of software
I would recommend taking it one level deeper, so that
1) cleaner directory structure
2) project oriented structure

e.g.: /big/dom/xdomain/project01/
/big/dom/xdomain/project01/tmp
/big/dom/xdomain/project01/bin
...
/big/dom/xdomain/project01/usr

This way, you won't paint yourself into a corner, and can easily do:
$du -cs project01

to calculate your disk usage much easier...

:)

--
Terra
--Looks like an AOTA article to me--
FutureQuest

Matt
11-13-2001, 04:44 PM
Good point Terra... this is a great way to keep projects separate from one another.

Hi Slim. Generally if a Perl module is not already installed on FutureQuest, I evaluate just how badly I need the module. I try to determine whether it is absolutely necessary to have the Perl module installed, or if there is some alternative solution. If I make the determination that a Perl module installation is the only way to go, I make a support request for installation (make sure to let FutureQuest know what server you're on). Some people make requests for Perl module installations here in the forums. Generally if FutureQuest will not install the module for you, they'll provide a reason why. This should give you enough information to make a more informed decision about installing a module locally. :)

-Matt