A Beginner's Guide to Compiling Source Code

 in
If you've been hesitant to compile Linux source code, hesitate no more—this article gives complete instructions for your first foray.
A Few Hints

In several instances I've failed miserably with a source distribution, then weeks or months later downloaded a later version and had it compile cleanly. Perhaps I updated a library the Makefile was looking for, or perhaps the author made a change in the source which fortuitously caused the program to be compatible with my system. In other words, it's worthwhile to try again later when you initially have a problem.

Another situation I've found myself in: after several edits of the Makefile and perhaps a few header files I'm getting more and more compiler errors. Nothing seems to work and I can't seem to make any headway. This is an ideal time to delete the entire directory tree and reinstall it from the archive file. Sometimes a completely fresh start helps.

One compiler flag to watch out for in the Makefile is -g (as in gcc -g). The GNU programs often have this flag, which instructs the compiler to add bulky debugging code to the executable. This is needed if you plan to use a debugger on the program. I don't even have a debugger installed, so I routinely remove that flag. The strip utility will remove this debugging code, often reducing an executable to half its original size.

Virtual consoles are tailor-made for compiling. Once you've set a lengthy compilation in motion, just switch to another console and start something else. I like to shut down X-Windows while compiling, as gcc uses all of the processor cycles it can get. The more resources that are available, the faster your program will compile.

Conclusion

So what do you gain from learning to compile programs?

  • The range of software available to you is considerably increased.

  • I believe there is an advantage to using an executable tuned to your system and configuration.

  • You have the opportunity to specify compiler flags, like >\#140>O2, to optimize the code. Sometimes there are compile-time options that can be set or unset in the Makefile.

  • Functions or subroutines in the program you know you will never need can be left out of the executable.

  • Source code is often the only form in which successive builds are available in beta-testing scenarios.

  • Often more complete documentation will be included with source code than with a binary distribution.

  • It is interesting to get glimpses into the way programs are put together. Often source files are heavily commented, because the programmer might want to explain sections of code to present or future collaborators in the project.

Larry Ayers (layers@vax2.rain.gen.mo.us) lives on a small farm in norther Missouri, where he is currently engaged in building a timber-frame house for his family. He operates a portable band-saw mill, does general woodworking, plays the fiddle and searches for rare prairie plants, as well as growing shiitake mushrooms. He is also struggling with configuring a Usenet news server for his local ISP.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The article had nothing that

Anonymous's picture

The article had nothing that would help anybody to compile anything. You are only explaining the technology. The title is very misleading.

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState