Guidance: Compile Education

Home » CentOS » Guidance: Compile Education
CentOS 3 Comments

This question may not belong in the CentOS.org list, but I do want to compile against this distro. Please advise.

The question:

Can I be pointed at methods to learn to compile source against a distro. I have software development background (but too long ago to be specifically useful; however I have the concepts). Typically I can find some fairly decent step-by-steps for some apps, but it never works out. Which means I am missing the basics.

I have been working with CentOS and Fedora through many VM and metal installs, so that part is OK. I am getting tired of constantly trying to find the app I want in the distro, or an applicable rpm. It’s time to compile.

Stan

3 thoughts on - Guidance: Compile Education

  • I think you need to ask a more specific question, but this is an overview of the process to give you a place to start with further reading. Google is your friend here.

    To compile programs, you need to install a compiler (usually gcc) and whatever development libraries are required. Those are usually named something-devel, so if you are compiling a program that uses the SDL library, for example, you need to install the SDL-devel rpm as well.

    A lot of software comes with configure and make scripts. If that’s the case, you can compile it by moving into the source directory and typing ./configure (with the dot and slash), then make. Configure sometimes comes with options for where to install the software after compiling it. If that’s the case, type ./configure –prefix –prefix=/path/to/your/directory instead of just typing ./confgure alone. After running make, run make install to install the software.

    This procedure works, but I personally avoid it if possible. It’s usually a better idea to install rpms on a CentOS system. The effort required to create a rpm for any particular program ranges from absolutely trivial to next to impossible.

    If you want to create and/or recompile rpms, you should install rpmdevtools, then run rpmdev-setuptree to create a rpm build tree in your home directory. Otherwise you will have to compile rpms as the root user which is possible but generally not a really good idea. (rpmdevtools does a lot of other handy stuff, too.)

    The easiest way to create a new rpm (assuming that one doesn’t already exist) is to edit an existing spec file for something that’s as similar to what you are trying to do as possible.

    In many cases you can find an existing rpm for the program that you’re trying to install as a Fedora rpm. If that’s the case, download and recompile the Fedora .src.rpm and it will in many cases work perfectly. Sometimes you need to make some small changes in the spec file but a lot of the time you don’t even have to do that.

  • The best approach depends very much on the target application and how you intend to mange it. Most sources will have a generic configure script and makefile that will build and maybe install in /usr/local. For a quick test, that might be enough, but you have to note where things land and clean up after yourself.

    Note that ‘most’ things worth building have already been packaged as RPMs, so finding them is still going to be your easiest solution. If they are for a ‘slightly’ wrong disto, you can often grab the source rpm instead of the binary and ‘rpmbuild –rebuild …’ to get locally configured binary rpms. The somewhat higher level approach to this is to install the ‘mock’ package from epel and then ‘mock -r some_version –rebuild some_src.rpm’. This will download all of the required library support and build the binary rpm for some fedora/CentOS other than the running system. There are lots of variations, but these may get something working without a lot of specific programming knowledge.

    One other thing to know about would be ‘software collections’ that have updated versions of applications that can co-exist with the stock versions. This might come into play if you run across source that uses c++11 and you want to compile it on CentOS 6 (thus needing a newer gcc, etc.).

  • Excellent. This gives a nice range of options. I tried mock – the first build failed so I tried a different src rpm and it worked. Installed fine. I now have gnome-commander on xfce4/CentOS7.

    Many thanks. Lots to do now…..

    Stan

    Sent from my iPhone