Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > 66ff8a1298a082e86e45594a1ef51dda > files > 10

faq-1.0-3mdk.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
 <TITLE>Linux Frequently Asked Questions with Answers: Porting, compiling and obtaining programs </TITLE>
 <LINK HREF="Linux-FAQ-6.html" REL=next>
 <LINK HREF="Linux-FAQ-4.html" REL=previous>
 <LINK HREF="Linux-FAQ.html#toc5" REL=contents>
</HEAD>
<BODY>
<A HREF="Linux-FAQ-6.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="Linux-FAQ-4.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="Linux-FAQ.html#toc5"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="Porting, compiling and obtaining programs"></A> <A NAME="s5">5. Porting, compiling and obtaining programs </A></H2>

<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="How do I compile programs?"></A> <A NAME="ss5.1">5.1 How do I compile programs? </A>
</H2>

<P>Most Linux software is written in C and compiled with the GNU C
compiler.  GCC is a part of every Linux distribution.  The latest 
compiler version, documentation, and patches are on 
<A HREF="ftp://ftp.gnu.org/pub/gnu/">ftp://ftp.gnu.org/pub/gnu/</A>.
<P>Programs that are written in C++ must be compiled with the GNU G++
compiler, which is also included in Linux distributions and available
from the same place as GCC.
<P>To build version 2.0.x kernels, you will need GCC version 2.7.2.x.
Trying to build a Linux kernel with a different compiler, like 
GCC 2.8.x, EGCS, or PGCC, may cause problems until code dependencies 
of the 2.7.2.x compilers are fixed.  
<P>Information on the EGCS compiler is at htmlurl
url="http://egcs.cygnus.com" name="http://egcs.cygnus.com">.
<P>Note that at this time, the kernel developers are not answering bug
requests for 2.0.x version kernels, but instead are concentrating on 
developing 2.1.x version kernels.
<P>[J.H.M. Dassen]
<P>-------------------------------------------------------------------------------
<P>
<P>
<H2><A NAME="How do I port XXX to Linux?"></A> <A NAME="ss5.2">5.2 How do I port XXX to Linux? </A>
</H2>

<P>In general, Unix programs need very little porting.  Simply follow the
installation instructions.  If you don't know--and don't know how to
find out--the answers to some of the questions asked during the
installation procedure, you can guess, but this tends to produce buggy
programs.  In this case, you're probably better off asking someone
else to do the port.
<P>If you have a BSD-ish program, you should try using
<CODE>-I/usr/include/bsd</CODE> and <CODE>-lbsd</CODE> on the appropriate
parts of the compilation lines.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="What is ld.so and where do I get it?"></A> <A NAME="ss5.3">5.3 What is ld.so and where do I get it? </A>
</H2>

<P><CODE>Ld.so</CODE> is the dynamic library loader.  Each binary using
shared libraries used to have about 3K of start-up code to find and
load the shared libraries.  Now that code has been put in a special
shared library, <CODE>/lib/ld.so</CODE>, where all binaries can look for
it, so that it wastes less disk space, and can be upgraded more
easily.
<P><CODE>Ld.so</CODE> can be obtained from 
<A HREF="ftp://tsx-11.mit.edu/pub/linux/packages/GCC/">tsx-11.mit.edu/pub/linux/packages/GCC/</A> and mirror sites.  The
latest version at the time of writing is <CODE>ld.so.1.9.5.tar.gz</CODE>.
<P><CODE>/lib/ld-linux.so.1</CODE> is the same thing for ELF (``
<A HREF="Linux-FAQ-8.html#What's all this about ELF?">What's all this about ELF?</A>
'') and comes in the same package as
the <CODE>a.out</CODE> loader.
<P>-------------------------------------------------------------------------------
<H2><A NAME="How do I upgrade the libraries withough trashing my system?"></A> <A NAME="ss5.4">5.4 How do I upgrade the libraries withough trashing my system?  </A>
</H2>

<P>
<P>Note: You should always have a rescue disk set ready when you perform
this procedure, in the likely event that something goes wrong!
<P>This procedure is especially difficult if you're upgrading very old
libraries like libc4. But you should be able to keep libc4 on the same
system with libc5 libraries for the programs that still need them.
The same holds true for upgrading from libc5 to the newer-yet glibc2
libraries.
<P>The problem with upgrading dynamic libraries is that, the moment you
remove the old libraries, the utilities that you need to upgrade to
the new version of the libraries don't work.  There are ways around
around this.  One is to temporarily place a spare copy of the run
time libraries, which are in /lib/, in /usr/lib/, or /usr/local/lib/,
or another directory that is listed in the /etc/ld.so.conf file.
<P>For example, when upgrading libc5 libraries, the files in /lib/ might
look something like:
<P>
<PRE>
libc.so.5
libc.so.5.4.33
libm.so.5
libm.so.5.0.9
</PRE>

These are the C libraries and the math libraries.  Copy them to
another directory that is listed in /etc/ld.so.conf, like /usr/lib/.
<P>
<PRE>
cp -df /lib/libc.so.5* /usr/lib/
cp -df /lib/libm.so.5* /usr/lib/
ldconfig
</PRE>

Be sure to run ldconfig to upgrade the library configuration.
<P>The files libc.so.5 and libm.so.5 are symbolic links to the actual
library files.  When you upgrade, the new links will not be created if
the old links are still there, unless you use the -f flag with cp.
The -d flag to cp will copy the symbolic link itself, and not the file
it points to.
<P>If you need to overwrite the link to the library directly, use the -f
flag with ln.
<P>For example, to copy new libraries over the old ones, try this.  Make
a symbolic link to the new libraries first, then copy both the libraries
and the links to /lib/, with the following commands.
<PRE>
ln -sf ./libm.so.5.0.48 libm.so.5
ln -sf ./libc.so.5.0.48 libc.so.5
cp -df libm.so.5* /lib
cp -df libc.so.5* /lib
</PRE>

Again, remember to run ldconfig after you copy the libraries.
<P>If you are satisfied that everything is working correctly, you can
remove the temporary copies of the old libraries from /usr/lib/ or
wherever you copied them.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="Has anyone ported / compiled / written XXX for Linux?"></A> <A NAME="ss5.5">5.5 Has anyone ported / compiled / written XXX for Linux? </A>
</H2>

<P>First, look in the Linux Software Map--it's at 
<A HREF="ftp://sunsite.unc.edu/pub/Linux/docs/linux-software-map">sunsite.unc.edu/pub/Linux/docs/linux-software-map</A>, and on the
other FTP sites.  A search engine is available on the World Wide Web
at 
<A HREF="http://www.boutell.com/lsm/">http://www.boutell.com/lsm/</A>.
<P>Check the FTP sites (``
<A HREF="Linux-FAQ-2.html#Where can I get Linux material by FTP?">Where can I get Linux material by FTP?</A>
'') first--search the <CODE>ls-lR</CODE> or <CODE>INDEX</CODE> files
for appropriate strings.
<P>Also look at the Linux Projects Map, 
<A HREF="ftp://ftp.ix.de/pub/ix/Linux/docs/Projects-Map.gz">ftp.ix.de/pub/ix/Linux/docs/Projects-Map.gz</A>.
<P>There's a search engine for Linux FTP archives at
http://lfw.linuxhq.com/
<P>Also check out the Freshmeat Web site 
<A HREF="http://www.freshmeat.org">http://www.freshmeat.org</A>,
which is really cool.  (``
<A HREF="Linux-FAQ-8.html#What online/free periodicals exist for Linux?">What online/free periodicals exist for Linux?</A>
'' 
<P>If you don't find anything, you could download the sources to
the program yourself and compile them.  See ``
<A HREF="#How do I port XXX to Linux?">How do I port XXX to Linux?</A>
'' If it's a large package that may require some
porting, post a message to <CODE>comp.os.linux.development.apps</CODE>.
<P>If you compile a large-ish program, please upload it to one or more of
the FTP sites, and post a message to <CODE>comp.os.linux.announce</CODE>
(submit your posting to 
<A HREF="mailto:linux-announce@news.ornl.gov">linux-announce@news.ornl.gov</A>).
<P>If you're looking for an application program, the chances are that
someone has already written a free version.  The
<CODE>comp.sources.wanted</CODE> FAQ has instructions for finding the
source code.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="Can I use code or a compiler compiled for a 486 on my 386?"></A> <A NAME="ss5.6">5.6 Can I use code or a compiler compiled for a 486 on my 386? </A>
</H2>

<P>Yes, unless it's the kernel.
<P>The -m486 option to GCC, which is used to compile binaries for x486
machines, merely changes certain optimizations.  This makes for slightly
larger binaries that run somewhat faster on a 486.  They still work fine
on a 386, though, with a small performance hit.
<P>However, from version 1.3.35 the kernel uses 486 or Pentium-specific
instructions if configured for a 486 or Pentium, thus making it unusable
on a 386.
<P>GCC can be configured for a 386 or 486; the only difference is that
configuring it for a 386 makes -m386 the default and configuring for a 486
makes -m486 the default.  In either case, these can be overridden on a
per-compilation basis or by editing /usr/lib/gcc-lib/i*-linux/n.n.n/specs.
<P>There is an Alpha version of GCC which knows how to do optimization well
for the 586, but it is quite unreliable, especially at high optimization
settings.  The Pentium GCC can be found on tsx-11.mit.edu in
/pub/linux/ALPHA/pentium-gcc.  I'd recommend using the ordinary 486 GCC
instead; word has it that using -m386 produces code that's better for the
Pentium, or at least slightly smaller.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="What does gcc -O6 do?"></A> <A NAME="ss5.7">5.7 What does gcc -O6 do? </A>
</H2>

<P>Currently, the same as -O2 (GCC 2.5) or -O3 (GCC 2.6, 2.7).  Any number
greater than that does the same thing.  The Makefiles of newer
kernels use -O2, and you should probably do the same.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="Where are linux/*.h and asm/*.h?"></A> <A NAME="ss5.8">5.8 Where are linux/*.h and asm/*.h? </A>
</H2>

<P>The files <CODE>/usr/include/linux/</CODE> and
<CODE>/usr/include/asm/</CODE> are often soft links to the 
directories where the kernel headers are.  They are usually under
/usr/src/kernel*/.
<P>If you don't have the kernel sources, download them--see, ``
<A HREF="Linux-FAQ-7.html#How do I upgrade/recompile my kernel?">How do I upgrade/recompile my kernel?</A>
''
<P>Then, use <CODE>rm</CODE> to remove any garbage, and <CODE>ln</CODE> to create
the links:
<PRE>
rm -rf /usr/include/linux /usr/include/asm
ln -sf /usr/src/linux/include/linux /usr/include/linux
ln -sf /usr/src/linux/include/asm /usr/include/asm
</PRE>

<CODE>/usr/src/linux/include/asm/</CODE> is a symbolic link to an
architecture-specific asm directory--if you have a freshly
unpacked kernel source tree, you must make symlinks.  You'll also find
that you may need to do `make config' in a newly-unpacked kernel source
tree, to create linux/autoconf.h.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="I get errors when I try to compile the kernel."></A> <A NAME="ss5.9">5.9 I get errors when I try to compile the kernel. </A>
</H2>

<P>See the previous question regarding the header files.
<P>Remember that when you apply a patch to the kernel, you must use the
<CODE>-p0</CODE> or <CODE>-p1</CODE> option: otherwise, the patch may be
misapplied.  See the <CODE>patch</CODE> manual page for details.
<P>``<CODE>ld: unrecognized option `-qmagic'</CODE>'' means that
you should get a
newer linker, from 
<A HREF="ftp://tsx-11.mit.edu/pub/linux/packages/GCC/">ftp://tsx-11.mit.edu/pub/linux/packages/GCC/</A>, in the file
<CODE>binutils-2.8.1.0.1.bin.tar.gz</CODE>.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="How do I make a shared library?"></A> <A NAME="ss5.10">5.10 How do I make a shared library? </A>
</H2>

<P>For ELF,
<PRE>
   gcc -fPIC -c *.c
   gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o
</PRE>

For <CODE>a.out</CODE>, get tools-n.nn.tar.gz from tsx-11.mit.edu, in
/pub/linux/packages/GCC/src/.  It comes with documentation that will
tell you what to do.  Note that <CODE>a.out</CODE> shared libraries are a
very tricky business.  Consider upgrading your libraries to ELF
shared libraries.  See the ELF HOWTO, at  
<A HREF="ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/">sunsite.unc.edu/pub/Linux/docs/HOWTO/</A> 
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="My executables are (very) large."></A> <A NAME="ss5.11">5.11 My executables are (very) large. </A>
</H2>

<P>With an ELF compiler (``
<A HREF="Linux-FAQ-8.html#What's all this about ELF?">What's all this about ELF?</A>
''), the
most common cause of large executables is the lack of an appropriate
.so library link for one of the libraries you're using.  There should
be a link like libc.so for every library like libc.so.5.2.18.
<P>With an <CODE>a.out compiler</CODE> the most common cause of large
executables is the <CODE>-g</CODE> linker (compiler) flag.  This produces
(as well as debugging information in the output file) a program which
is statically linked--one which includes a copy of the C library
instead of a dynamically linked copy.
<P>Other things worth investigating are <CODE>-O</CODE> and <CODE>-O2</CODE>,
which enable optimization (check the GCC documentation), and
<CODE>-s</CODE> (or the strip command) which strip the symbol information
from the resulting binary (making debugging totally impossible).
<P>You may wish to use <CODE>-N</CODE> on very small executables (less than
8K with the <CODE>-N</CODE>), but you shouldn't do this unless you
understand its performance implications, and definitely never with
daemons.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="Does Linux support threads or lightweight processes?"></A> <A NAME="ss5.12">5.12 Does Linux support threads or lightweight processes? </A>
</H2>

<P>As well as the Unix multiprocessing model involving heavyweight processes,
which is of course part of the standard Linux kernel, there are several
implementations of lightweight processes or threads.  Recent kernels
implement a thread model, kthreads.  In addition, there are the
following packages available for Linux.
<UL>
<LI>GNU glibc2 for Linux has optional support for threads.  The
archive is available from the same place as glibc2, 
<A HREF="ftp://ftp.gnu.org/pub/gnu">ftp://ftp.gnu.org/pub/gnu</A></LI>
<LI>In sipb.mit.edu:/pub/pthread or ftp.ibp.fr:/pub/unix/threads/pthreads.
Documentation isn't in the package, but is available on the World Wide
Web at http://www.mit.edu:8001/people/proven/home_page.html.  Newer
Linux libc's contain the pthreads source.  The GNU Ada compiler on
sunsite.unc.edu in /pub/Linux/devel/lang/ada/gnat-3.01-linux+elf.tar.gz
contains binaries made from that source code.</LI>
<LI>In ftp.cs.washington.edu:/pub/qt-001.tar.Z is QuickThreads.  More
information can be found in the technical report, available on the same
site as /tr/1993/05/UW-CSE-93-05-06.PS.Z.</LI>
<LI>In gummo.doc.ic.ac.uk/rex/ is lwp, a very minimal implementation.</LI>
<LI>In ftp.cs.fsu.edu:/pub/PART/, an Ada implementation.  This is useful
mainly because it has a lot of Postscript papers that you'll find useful
in learning more about threads.  This is not directly usable under
Linux.</LI>
</UL>

Please contact the authors of the packages in question for details.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="Where can I get `lint' for Linux?"></A> <A NAME="ss5.13">5.13 Where can I get `lint' for Linux? </A>
</H2>

<P>Roughly equivalent functionality is built into GCC.  Use the -Wall
option to turn on most of the useful extra warnings.  See the GCC
manual for more details (type control-h followed by i in Emacs and
select the entry for GCC).
<P>There is a freely available program called `lclint' that does much the
same thing as traditional lint.  The announcement and source code are
available at on larch.lcs.mit.edu in /pub/Larch/lclint/; on the World Wide
Web, look at http://larch-www.lcs.mit.edu:8001/larch/lclint.html.
<P>-------------------------------------------------------------------------------
<P>
<H2><A NAME="Where can I find kermit for Linux?"></A> <A NAME="ss5.14">5.14 Where can I find kermit for Linux? </A>
</H2>

<P>Kermit is distributed under a non-GPL copyright that makes its
terms of distribution somewhat different.
The sources and some binaries are available on 
<A HREF="ftp://kermit.columbia.edu">kermit.columbia.edu</A>.
<P>The WWW Home Page of the Columbia University Kermit project is 
<A HREF="http://www.columbia.edu/kermit/">http://www.columbia.edu/kermit/</A>. 
<P>===============================================================================
<P>
<HR>
<A HREF="Linux-FAQ-6.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="Linux-FAQ-4.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="Linux-FAQ.html#toc5"><IMG SRC="toc.gif" ALT="Contents"></A>
</BODY>
</HTML>