Ubuntu-Classroom: Basic Compiling

Presenting the Classroom‘s third class, Basic Compiling. One of the great benefits of Linux and Free and Open Source Software, in general, is the ability to compile software. This opens up new possibilities on how the software will be installed and perform on different systems (but that’s for a more advanced topic). This class introduces novice users on two of the safer and more recommended ways of compiling software.

Summary: This class on Basic Compiling covers two of the preferred methods of compiling. The first is using the famous trio of commands: “./configure”, “make”, and “checkinstall”, the last command being a substitute of “make install”. While “make install” is the more famous command, “checkinstall” is more recommended because it creates a package that could be easily kept, reinstalled, and removed. Using this three commands, a user can compile most of the source code available. The second method is compiling and building packages using APT (Advanced Packaging Tool). This method is even more recommended since it downloads the necessary dependencies (files, libraries and programs needed by a particular package/program) of the package that the user is trying to build. This method also allows users of one Linux distribution to use the source code of another compatible distribution to compile packages. The world of compiling packages is far wider and more complicated (but definitely more exciting) than this, but these two methods are enough to set new users on that path.


Note: This is the edited and formatted text of my IRC log of the Ubuntu Classroom session held last September 2, 2006 18:00 UTC and September 3, 2006 04:00 UTC on the topic “Basic Compiling”. I have only edited the text in order to present it in an easily readable format. The contents are exactly the same (except in some instances where a small portion had to be relocated in order to place it in the proper context). The contents of the text are not mine but are just the output of the IRC client’s logging feature. Thus the contents belong to the instructor who gave them.

Instructors:

  • gnomefreak – installing using checkinstall
  • nalioth – compiling using apt

Compiling using configure, make, checkinstall

Hello thank you all for coming to this class on Basic Compiling. nalioth and myself [gnomefreak] will be today’s instructors. We will start off with a brief lecture, than off to compiling an app. The app we will be compiling today is GNU hello.

Let’s talk a little about compiling first. Here are some things you will need to know before we start. It’s a good idea to be familiar with the terminal and basic commands like “cd” and “tar” and “apt-get” commands. You can find more information for the tar command and its uses on the man page. Type “man tar” in terminal to read the man page. You will also need to have all supported repos enabled, (not for today’s example but other apps you choose to compile). Today i will be giving you most of the commands you will need to compile GNU hello. Not all apps are this easy to compile. I choose GNU hello because its easy and short to compile. There are also different ways to compile an app. I will only be going over one way to do it. nalioth will be going over another way to compile an app.

You will need to tools installed before we start. Install build-essential and checkinstall (“sudo apt-get install build-essential checkinstall“). You don’t need checkinstall but i use it instead of make install because it will create a .deb file for the app you are compiling, (not always the case but most of the time). here is a link to read up on checkinstall: https://help.ubuntu.com/community/CheckInstall

Lets do it! Please download the tar from http://ftp.gnu.org/gnu/hello/ to your home directory (this is where we will be working from today). The file you want is the very last one that reads “hello-2.1.1.tar.gz 09-Jun-2002 02:33 380k“. Once download is complete you will want to untar it. I use “tar -xvzf hello-2.1.1.tar.gz“. without the ” [quotes]. It will than scroll output on you screen. Those are files its unpacking from the tar. When that’s done you want to “cd” into the newly created folder. “cd hello[Tab]”. [Tab] means to use the Tab key to complete the folder name. Once inside that directory it is a good idea to read over the INSTALL and README files. they are in this folder. For today’s example its not needed (but always a good idea). Now run “./configure –help” today we will be doing a basic compile so its not needed to read it. If you want to change the “default program settings” you would use some of the options listed in the –help page. The command ./configure –help is just so you see the options you are able to use. for today we are just gonna use ./configure. Now please type “./configure” as we will be using default settings.. If everything was done as i have explained it should end without errors. Next we want to run “make“. this is going to read the make file of the app. make on this app shouldn’t take longer than a minute.

Now here is where you either want to run “sudo make install” or “sudo checkinstall“. I prefer checkinstall so we will do it that way for today. Once you run “sudo checkinstall” it will ask you a few questions. The first question is something like “what would you like to name it” You can choose a name or just hit [Enter] without choosing one.

nalioth: checkinstall is the preferred method for Ubuntu. checkinstall produces debs that you can keep for later use, and are custom made for your particular machine. If your source code is miswritten [poorly/wrongly written], and the program doesn’t work, using checkinstall to create a deb will allow easy removal of your freshly compiled program. If you use “make install“, you’ll end up with pieces of your program all over the system (which makes it difficult to remove if things go bad)

When it gets done you will see that checkinstall installed a .deb that it made for you and gives instructions on how to remove it if you wanted to remove the app. Also shows you where it was installed. Now type “cd” when its done. When back in home directory you should be able to type “hello” at the prompt and it should run.

Congrats everyone on your first compiling of a program. Don’t forget this was an easy example, please don’t expect all apps to compile this easy without errors. Thank you for coming to today’s class.


Compiling using APT

OK, many of you are aware of apt-get, but are you aware that apt-get can compile packages for you? If you will all type “less /etc/apt/sources.list” in your consoles/terminals, you’ll see your sources.list. If you look at your sources.list, you’ll see lines beginning with ‘deb-src’. Those are the repositories that contain source code for all your packages. some of you may have those lines commented out (with an # in front of them). Now you may type “q” to leave “less” and if your deb-src lines were commented out, please take a moment to remove the # from the beginnings of those lines (you may leave the # in front of the lines with ‘backports’ in them, as backports are sometimes squirrelly)

OK, for those of you who uncommented your sources.list, please update your apt-get. OK, now the first thing to do to get apt-get to compile your program of choice is to type “sudo apt-get build-dep $PKG”. This will install any necessary dependencies to build the program. If you wish, you may type “sudo apt-get build-dep aee” [Enter] at this time. OK, now we can type “sudo apt-get -b source aee” [Enter]. What the above command does is: tells apt-get to download and build a deb from a source package. When all the activity is finished, you’ll have a deb in the current directory. Unlike checkinstall, using apt-get to build pkgs [packages] creates “official” debs that can be shared. checkinstall created packages are not ‘official’ and may not work well if shared with others.

The reason I’ve covered using apt-get to build pkgs [packages] is that using debian binaries in Ubuntu will break Ubuntu, but using apt-get to build from debian deb-src repositories is perfectly fine. So if you just have to have something that only debian offers, you can use apt-get to safely build a pkg from debian’s source repos

.

Questions and Answers

  • Q. is it normal that the first question I was asked in checkinstall was about the package documentation directory?
    A1. OK, in using checkinstall, choosing the default answers is fine. The ‘package documentation directory’ is something that is used by checkinstall, and can be deleted after the checkinstall process is finished.
    A2. Yes, it was different for me because i ran it again and it only asks the first question once.
  • Q. so unlike checkinstall, apt-get -b doesn’t install the package automatically?
    A. No, it just creates a pkg. After apt-get creates it, you may click on it and gdebi will install it for you or you may use dpkg from the command line. sudo dpkg -i file.deb [Editor’s Note: Kubuntu users would have to right-click on the package and select “Kubuntu Package Menu” then “Install Package”]
  • Q. Did others notice that update-notifier offers an update for hello?
    A. The reason is: the version of hello you guys downloaded is inferior in version number to the one in the Ubuntu repos.
  • Q. if we build from source a package that’s found in the repositories, what will happen if an update was made available for it? What would we do? Can we safely upgrade to that new version in the repositories? or do we have to recompile?
    A. If its installed you will get updates The package is installed it should be able to be upgraded normally.
  • Q. I wonder why no one asks why you have to do “./configure” rather than just “configure”
    A1. The configure file is a script so you run it with ./
    A2. That basically is a difference in how bash handles the PATH. Windows cmd.exe always search “.” before anything in PATH. It [BASH] never even looks in “.” until you add . to the PATH variable. Some people do this “export PATH=.:$PATH”
  • Q. What does “sudo apt-get build-dep” actually do? I know that “sudo apt-get -b source” is the one that actually builds/compiles the package.
    A. sudo apt-get build-dep kvirc (for an example) would go through your apt database and install all the necessary packages to build kvirc from source. these might include kde development libs, development tools you may not have installed, widget libraries, etc
  • Q. Where does the source code for the package get downloaded to?
    A. It downloads to the current directory

Review: This is probably the shortest of the three classes so far, and the class was only prolonged (perhaps to the agony of the other students) by questions from your truly. Class participation is also noticeably lower compared to the previous classes. Is it because of a lack of advertisement? An inconvenient time (although there were more active participants in previous classes on with same time schedule)? I presumed that the topic would have attracted some attention, based on the amount of “how do I compile this?” questions in the forums and IRC. Well, whoever wasn’t there missed out the chance to ask questions and learn a lot. The instructors can only present what they have prepared. Additional ideas and information would only be brought out through questions from the students. Anyway, for those who missed the class, this transcript is for you. But next time, try to be there. (^_^)


4 thoughts on “Ubuntu-Classroom: Basic Compiling

  1. How do I compile a program with the optimize flag (I think it’s -03) for speed? Can I set the -03 flag in a gcc config file or can I use -03 with the make command?

    Also, when we run ./configure are we running a shell script provided by the program developer?

  2. Pingback: visit here
  3. Citation:
    A1. The configure file is a script so you run it with ./

    This is wrong. Wether you have to use ./ or not is totally independant from wether the executable is a script or something else. Answer 2 is better, even if this behaviour isn’t limited to the bash shell.

  4. What do we do if we get : “Make is out of date” error or something like this….
    and it keeps on looping on the config file again and again…
    Please help me on this..

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.