How To Build A Typical Linux Project
If you are using Linux, it makes a lot of sense to download and use various Free and Open Source software. While frequently you will be able to download and install various RPMs, there are a lot of projects that do not provide any user friendly installers. Some projects even do not have the explicit releases. From the other side, building from the source may produce an application that is much better optimized to your processor and operating system. Surely, you must also be able to build a Free / Open Source project if you want to master it enough to join as developer later.
If the project has no explicit releases, you may need to pull the source code directly from its CVS or SVN repository. The websites of most such projects will have the corresponding command line which you only need to copy-paste to your system, for instance cvs -z3 -d:pserver:firstname.lastname@example.org:/sources/classpath co classpath. The similar command usually downloads a large number of project files in a current folder.
Look into the files README and INSTALL that should be at the top folder in the downloaded project. They may contain valuable information that will save you a lot of time.
Some projects provide the build script as a shell script (usually named build.sh). This is not very frequent, but happens for very old projects and also for new projects that try to provide a “user friendly” build procedure. If you find such file, try to use it first (the installation may be placed in a separate script that is usually named install.sh). If you find these scripts, just run them. Otherwise, proceed to the following steps.
Search for the file called configure which also must be present in a project top folder. It is usually a .sh script that will tune the project build system to your machine. If you find it, type ./configure or sh configure to run this script. ./configure usually has a lot of options that may help if the “default” run fails with error messages. Run the script with the key –help to see the options. If there is no configure script, it may be an old – style project which only uses makefiles, so you can proceed directly to the next step.
Search for the file called makefile which may be initially present or appear after you run configure. If you find it, type the command make. It should find the makefile in the current directory and build the project for you.
If there is no configure nor makefile in the project tree, it may be an ant – powered project with the build.xml file instead. In this case, type ant in the project root folder. While make is more popular for C and C++ projects, ant is popular for java projects.
If ant doesn’t work either, or the project is C or C++, try running ./autogen.sh to create the configure and makefile files. This uses autoconf, automake and libtool to create these files.
After you succeeded to compile the makefile – based project, try make install to place the project files into appropriate locations (to install the project). The default locations like /usr/lib or /usr/bin are usually only root-writeable, so this step usually needs administrator rights.
After the installation succeeds, try to type the short project name. This usually invokes the newly compiled and installed program which is now ready to use.
- If the build fails, paste the error message into Google or other web search engine. You will frequently find the description of the same problem together with explanation, how to solve it.
- The frequent reason is the absence or the wrong version of some required library. In this case all you need is to find and build this library which is usually a similar project on its own.
- If you still cannot understand that is going wrong, try to update your build tools and the existing C/C++/java or other libraries (depending on which programming languages are used in the project). It is usually easy to update tools and libraries using the system software updater.
- After you tried the earlier steps (but after, not before), send a question to the project mailing list. Tell all you think may be relevant about your operating system describe the problem in details and include all error messages. Hackers should understand that you have done enough from you side and really deserve some help.
- If you succeeded to build a program from the source, make use of this. Try to understand how does the program work and improve it!
- Sometimes programs do not compile with the latest compiler versions. In this case you can use an older version, or get a binary package from the internet or a friend.
- One common pitfall for someone who jumps onto linux environment will be copying the source folders from Windows. In this case, make can give weird errors due to difference in line endings. Always try using the source downloaded from the respective website for the specific operating system.
- Always try to solve the problem yourself, search the web for a solution, and check the mailing list archive before asking any question to the mailing list. Otherwise you may get something like RTFM in response which is rather frustrating and not very helpful.
- If the project has official releases, try to use them before pulling the source code from repository. The repository version may contain recently introduced bugs and be very unstable.
- From the other side, if the official release has problem, this problem may be already fixed on the CVS/SVN and in such case it may be worth to try the newest version.
- Some projects may be very difficult to build if your operating system is old and a lot of libraries are obsolete. In such case think about migrating to another Linux distribution that is under active development and should have the more recent versions of these libraries.