How do I compile a program?
The answer depends on what program you're referring to.
If the program you're trying to compile is not in C, you need to
follow that particular language's build procedure. Check the
documentation for the specific compiler you need - and this isn't
bad advice for gcc, Linux's C/C++ compiler, either.
However, since most common packages requiring compilation are in
C, here are some general guidelines.
If you have a single ".c" file - for example,
"tryIt.c" - and you're attempting to create an
executable, the command
cc -o tryIt tryIt.c
may work servicably for you. This assumes that tryIt.c
requires no nonstandard libraries or external modules, and has no
compilation errors.
If you're trying to compile a package that you got off the
Internet - for example, ncurses, which is a text-mode library - you
may also be able to use the following sequence in the top directory
of the package:
./configure --help # to see options for building
./configure
make
make install
make install should be done only after you've made sure the
package build properly, and should be done as root. For libraries,
you may also want to run /sbin/ldconfig -v to make sure
the library was installed properly, and some libraries may require
a modification to /etc/ld.so.conf, as well. Most packages
have an INSTALL document or a README file. Read
it, and you should be well-guided.
If you're trying to compile a program written for X, you may
have to replace ./configure in the example above with
xmkmf -a. You can get a quick indication of this if a file
called Imakefile in the source directories.
More information on each program mentioned here can be found in
the man pages, and each package normally has a README, as
mentioned.
If all of the above looks hard; it isn't really. You need some practice, that's all. If you're a serious linux power user (i.e. you don't spend your days in a nice GUI desktop reading mail and surfing the web), you'll get the hang of it soon enough. Remember, this stuff is supposed to be fun, don't get frustrated.
|