Thomson-Blog ( 学习,学习,再学习;努力,努力,再努力。)
在学习的路上不断成长,成功之路就在脚下。

  Sometimes, the typical sequence to compile a program doesn't work.It starts spitting out all kinds of errors and seems to do everythingbut compiling that annoying program already. What to do then? Thistutorial describes how to get rid of many frequently occuring errorsduring a typical Linux compiling sequence.

Note: Youshould only compile software when you really need to do it. Compilingcan be dangerous to your Linux installation. If you want to installsome software, please look for a precompiled package (like a .rpm or a.deb) first. If you really need to compile, do it with care.

Note:This tutorial assumes that you have some linux command line knowledgeand that you know how to work with your distro's package manager.

We can divide the errors in three categories:

  • ./configure errors
  • make errors
  • make install errors

Itshould be quite obvious how to recognize them: ./configure errors areoutputted by the configure script, make errors by the make command andso on. I'll now list common errors, with solutions, in these threecategories.

./configure errors

Thefollowing list contains some common errors that ./configure can give,sorted by frequency of appearance. The first one is the most occuringone. Things between ( and ) are optional, they do not always appear. Abold italic OR indicates that multiple errors have the same solution.Text between < and > describes the kind of string that shouldappear on that place.

  1. (configure:) (error:) <somename> (<someversion> (or higher)) not found. (Please check your installation!) OR checking for <somename>... (configure:) (error:) not found. OR(configure:) (error:) <somename> (<someversion> (or newer))is required to build <package-you're-trying-to-compile>
    • Thisusually means that the -dev or -devel version of the package with thename <somename> is not installed on your computer. Please useyour distro's package manager (or any other method to find and installpackages) to search for <somename> and install, if possible, the-dev or -devel version.

      If the -dev or -devel version is alreadyinstalled, or if it doesn't exist, have a look at the version numbercurrently installed. Is it high enough? If it is lower than<someversion> (if applicable), try upgrading the package. If thatis not an option for you, you can also try compiling an older versionof the package you're trying to compile. Older releases generally useearlier version of the libraries / programs they depend upon.

      Ifthe package that ./configure cannot find is a library (usuallyindicated by the package name being lib<something>), and you'resure you've got the right version installed, try to find the locationwhere the library's files are located. If this directory is notincluded in your ld conf file (which is usually located at /etc/ld.confor /etc/ld.so.conf) you should add it, and run ldconfig (usuallylocated at /sbin/ldconfig). Please note that ldconfig should usually beexecuted with root permissions. If you don't know how to do that, havea look at the first point of Make install errors.

      Note:If you don't have access to the ld conf file, you can also add thedirectory to the LD_LIBRARY_PATH variable. This is pretty ugly and notquite the best practice, but sometimes you don't have any otheroptions. You can add the directory to LD_LIBRARY_PATH this way:

      [rechosen@localhost ~]$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/your/library/directory                "

      Ofcourse, replace /your/library/directory with the applicable directoryin your case. Note that the LD_LIBRARY_PATH will also have to hold/your/library/directory when running the program you compiled.
  2. (configure:) (error:) cannot find header (file) <somename>.h OR (configure:) (error:) (header) (file) <somename>.h missing! OR <similar>
    • Theconfigure script can't find a .h file required for compilation. Thiserror is similar to the one above, as it requires you to install the-dev or -devel version of a certain package. However, it is usuallyless clear which package should be installed, as <somename> canbe a very generic name. Try searching the web for <somename>.h tofind out which package it belongs to, then try installing that package(including its -dev or -devel version, if available) using yourdistro's package manager.
  3. (configure:) (error:) no acceptable cc found in <somedirectories>
    • Yourgcc installation is either missing or the CC environment variable isnot set. Check if the package gcc is installed, using your distro'spackage manager. If it isn't, install it. If it is installed, however,try using this command:

      [rechosen@localhost ~]$ export CC="/usr/bin/cc"                                            

      Ifthat worked, you can add the command to your /etc/profile (a file fullof commands that are executed whenever any user logs in) so you won'thave to set it again.
  4. (configure:) (error:) C++ preprocessor "/lib/cpp" fails sanity check
    • Yourg++ package is either missing or corrupted. Please use your distro'spackage manager (or any other method to find and install packages) tosearch for g++ and install the corresponding package. Note that quitesome distro's do not call the package g++. Fedora, for example, usesthe packagename gcc-c++ in its yum repositories. If you can't find g++,try searching for c++, cpp and/or gcc.
  5. (configure:) (error:) C++ preprocessor "CC (-E)" fails sanity check
    • Thisis caused by a strange bug in certain versions of libtool that makesthe configure script check for all compilers supported by libtool. Thequickest solution is to install g++ (see the solution above this one).

Make errors

Asmake errors usually are too specific to make a nice list of genericones, I will give you a list of general things to do that might help:

  • Ifyou're compiling using gcc 4 (use gcc -dumpversion to find out), tryusing an older compiler version. First, make sure that some olderversion is installed. This can usually be detected this way:

    [rechosen@localhost ~]$ ls /usr/bin/gcc*                                        

    If that returns something like this:

    /usr/bin/gcc  /usr/bin/gcc32                                                              

    Thenyou can use, in this case, the gcc32 command to compile with an oldergcc version. If not, try using your distro's package manager to searchfor older versions of gcc (usually called something like compat-gcc orgcc-<versionnumber>). After installing, you should be able todetect the alternative gcc version using the ls command above. Tell the./configure, make and make install sequence to use the older gccversion in a way like this:

    [rechosen@localhost ~]$ CC="/usr/bin/gcc32" ./configure                         
    [rechosen@localhost ~]$ CC="/usr/bin/gcc32" make                                   
    [rechosen@localhost ~]$ CC="/usr/bin/gcc32" make install                       

    Note:in most cases, you can leave the /usr/bin away and just put the gccexecutable name. However, some non-standard Makefiles might handle itin a different way. Therefore, including the full path is the safestoption.

    Of course, replace the /usr/bin/gcc32 with the location of your alternative gcc command.
  • Sometimesmake errors are just caused by a plain bug. Try obtaining the latestdevelopment version of the software (using their cvs, svn or similarrepository, or by downloading a nightly snapshot) and try compilingthat one to see if they fixed the bug there.
  • Make errors canalso be caused by having wrong versions of certain libraries /programs. Especially very new and very old packages suffer from thisproblem. Have a look at the dependencies of the package (they areusually listed somewhere on the site of the software) and compare theversion numbers there with the version numbers on your own computer(they can usually be found using the search function of your distro'spackage manager). If the version numbers on your system are way higherthan the ones on the package's site, you are probably trying to compilea very old package. If you really need to compile it, try downgradingthe dependencies. However, it usually is a better option to search foran other way to install the package or to look for an alternative. Ifthe version numbers on your system are way lower than the ones on thepackage's site, you are either trying to compile a bleeding-edgepackage, or your distro is quite old, or both =). You could tryupdating the required libraries / programs or compiling an olderversion of the program. Also, have a look if a nice package made foryour distro of the program exists. Installing such a package is usuallyeasier than trying to deal with compilation errors.
  • Anotherthing to try is searching the web for your specific error. If you don'tfind anything useful, try stripping away things like line numbers (theycan change with versions), version numbers (you can replace them withan asterisk if they are contained in (file) names) andnon-alphanumerical characters like quotes, as they influence the searchengine's seeking. You can usually find a lot of information on mailinglists. Sometimes, a patch is provided that will fix the source code.Patches can be applied this way:

    [rechosen@localhost ~]$ patch -Np1 -i <patchfile>                                    

    Note that you will need to be in the source directory to apply a patch.

Make install errors

Theseerrors usually are quite easy to understand, but I'll document themanyway. There are two frequent causes that'll stop you from succesfullyusing make install:

  • You do not have root permission. Try running make install using sudo or try becoming root using su. Sudo should be used this way:

    [rechosen@localhost ~]$ sudo make install                                                 

    Itwill ask for a password; this usually is either your own password orthe system root password. You can use su to become root this way:

    [rechosen@localhost ~]$ su                                                                           

    Thiscommand will also ask for a password, but it always is the system rootpassword. After becoming root, just run make install as you'd donormally. And after that, don't forget to return to your normal useragain if you used su. You can do this by pressing Ctrl + D or, if thatdidn't work, typing 'exit' or 'logout' and then pressing enter.However, this is only recommended if you became root using su. The sudo program only runs a command with root permissions, it doesn't log you in as root.
  • The package you just compiled doesn't have the install target.In this case you will have to copy the compiled binaries to a bindirectory yourself. If you do an ls in the source directory, executablefiles should appear light-green. These files could be copied to/usr/bin (or /usr/local/bin, if you prefer) in a way like this:

    [rechosen@localhost ~]$ cp <executablefile> /usr/bin                           

    However,this will make a mess of your /usr directory if you use it too much.You could also add the directory in which the executable is located toyour PATH variable. Go to the directory, get the whole path of it thisway:

    [rechosen@localhost ~]$ pwd                                                                     

    Then paste the output of pwd into this command:

    [rechosen@localhost ~]$ export PATH="$PATH:<pwdoutput>"         

    Ifyou can just run the command now, it worked. Add the export command youran to your /etc/profile, so you won't have to type it again.

    Iagree that this isn't really a clean and easy way, but sometimesdevelopers don't take the time to create a (proper) install target. Weshould not be angry with them: think of all the work they do to let usenjoy useful and/or funny programs =).

Other problems

Here is a list of some other general problems, with solutions:

  • Everything went alright, but when I type the command I just installed bash says it cannot be found.This is usually caused by make install installing everything in/usr/local or in /opt/<packagename>. Have a look at the output ofmake install: where did it copy the files to? Try adding the bindirectory of that location to your PATH variable (the following exampleassumes the package was installed to /usr/local):

    [rechosen@localhost ~]$ export PATH="$PATH:/usr/local/bin"                       

    You can just replace /usr/local/bin with the bin directory in which theexecutables of your package were installed. If this works, add the lineto your /etc/profile so you won't have to type this again and again. Bythe way, you can control the place in which the package will beinstalled by specifying this option when running the configure script:

    [rechosen@localhost ~]$ ./configure --prefix=/usr                                             

    Replace/usr if necessary with the directory in which you'd like to have thepackage installed. Note that you are only setting the prefix; thebinaries will be installed in a subdirectory of the prefix, just likethe libraries, header files and so on. When using the above prefix, forexample, you will find the binaries in /usr/bin.
  • I want to install a very old version of a package, but I can't find the source archive of it on the internet.You still have a small chance. Try searching for rpm's of the versionyou want and download the corresponding src rpm. Unpack it this way:

    [rechosen@localhost ~]$ rpm2cpio <rpmfile> | cpio -idv                                    

    Now, use the source file that should have been extracted from the source rpm.

Final words

Thistutorial is not finished yet. I plan to update it every now and thenwith solutions to requests from users. Therefore, I ask you to commenton it and say what you'd like to see documented in it. Remember thatthis tutorial is about generic troubleshooting. Don't ask mehow to make a certain version of a certain program compile. Anyway, Ihope this tutorial has been useful to you. Thanks for reading and goodluck with that immersively complicated thing called compiling!

posted on 2010-01-19 11:17  Thomson-Blog  阅读(299)  评论(0编辑  收藏  举报