PDA

View Full Version : Compiling?



Jameson
06-23-2005, 05:44 AM
I've seen it used a million times but I really haven't got a clue what it means to Compile something.... out of all the books I've read I've been told to compile this or that... but I've never been told HOW to go about this compiling business...

Since this has the potential to take up pages in order to explain, I'd appreciate a link to a page that might shed a little light on this subject or perhaps this has been directed to an earlier post on the subject.

Thanks!

-Jameson

Harry Kuhman
06-23-2005, 06:05 AM
I've seen it used a million times but I really haven't got a clue what it means to Compile something....
This is way too broad of a subject for this forum. I'll give you a quick answer but understand that it will only scratch the surface. There is, however, plenty of information on the Internet that you can read once you get the basic comcept.

Not sure what all the book you read were, but this is covered pretty well in many of the books I've read.

In a nutshell (and simplifying things somewhat) there are two basic ways that computer languages work. Some languages are "interpreted" and some are "compiled". If a computer runs something written in an interpreted language (such as a DOS .bat file), it reads each line of the program and figures out what to do for that line and does it. The program stays in the form of a text file. For a compiled language (C, for example is almost always compiled) the computer translates the human readable text file into the computers own "op codes". These "op codes" can be run much faster than the computer trying to figure out what the human readable text file instructions are, at the small cost of the extra step or steps of the translation. What it means to compile is to run a program that takes the source program and do this translation (actually, the first step of the translation, there is usually also at least one more step, called "linking" that takes the output of the compiler and produces the final runnable .exe file.

There are many compilers for different languages. There are even many different compilers for the C language in Linux. One of these is evoked by the command cc at a shell prompt. A good place to start would be the man page for cc or maybe this webpage (http://www.computerhope.com/unix/ucc.htm).

Obviously (at least I hope it's obvious), teaching you how to program in C or any other language is way beyond what we do in this forum.

tdjokic
06-23-2005, 06:23 AM
Since this has the potential to take up pages in order to explainNo, it is very simple. Every driver or anything have some text file: "redme.1st" or something like that, and in this file you can see how to compile this driver: "Do that, do this, use this command..." and so on.

The basic form of a driver is in source code. This is good for every Linux, but you must prepare it - "compile" - for it. If somebody did it for you, than this is binary driver.

This is the general idea. Here is one example (not the best I am afraid):

(Name of the file is Readme.txt, and you get it after downloading and extracting file ltmodem-knoppix-2.4.27.tar.gz from http://linmodems.technion.ac.il/packages/ltmodem/Knoppix/)

To do the modem driver compile, it was necessary to
1) copy /usr/src/linux-2.4.27 to a hard drive partition with a Linux distro
2) set /usr/bin/gcc --> /usr/bin/gcc-2.95
because the 2.4.27 kernel was compiled with a compiler gcc version 2.95.4
-------
cat /proc/version
Linux version 2.4.27 (root-Koffer) (gcc version 2.95.4 20011002 (Debian
prerelease)) 2 SMP Mo Aug 9 00:39:37 CEST 2004
shows that the kernel+modulQ- were compiled with gcc version 2.95.4
------------

while the burnt into the Knoppix CD is:
root-ttyp1[knoppix] ls -l /usr/bin/gcc*
lrwxrwxrwx 1 root root 7 Jul 27 18:48 /usr/bin/gcc -> gcc-3.3
-rwxr-xr-x 1 root root 69960 Mar 10 2004 /usr/bin/gcc-2.95
-rwxr-xr-x 1 root root 85772 Aug 14 19:50 /usr/bin/gcc-3.3
lrwxrwxrwx 1 root root 10 Jul 27 18:48 /usr/bin/gccbug -> gccbug-3.3
-rwxr-xr-x 1 root root 16033 Aug 14 19:44 /usr/bin/gccbug-3.3
without any way to reset to gcc --> gcc-2.95

The ltmodem-8.26a.tar.gz was the resource for the compile.
The core of the compile looks like:
To begin compilation of lt_modem.o and lt_serial
................................... (I cut it here, tdjokic)

UnderScore
06-23-2005, 06:43 AM
Theory/History
http://en.wikipedia.org/wiki/Source_code
http://en.wikipedia.org/wiki/Compiler
http://computer.howstuffworks.com/c.htm

Applied
http://www.pcplus.co.uk/tutorials/default.asp?pagetypeid=2&articleid=4133&subsectionid=377

Jameson
06-23-2005, 06:47 PM
Ah many thanks to all! I've starting to grasp it, for some reason I just thought there was a good bit more to it...

-Jameson

Dave_Bechtel
06-23-2005, 06:54 PM
--There is, when you get _errors_ during the compile. ;-)

--Fortunately for you though, most of the things you can compile in Linux are error-free.


Ah many thanks to all! I've starting to grasp it, for some reason I just thought there was a good bit more to it...

-Jameson

Harry Kuhman
06-23-2005, 07:50 PM
Ah many thanks to all! I've starting to grasp it, for some reason I just thought there was a good bit more to it...
In some ways there is a lot more to it, in many ways the key information is available above. Underscore gave you some great links.

There are certainly many things we didn't cover (linkers, debuggers, assemblers, languages that are a combination of interpreting and compiling, development enviroments, macros, and plenty more). But you got a basic answer to what you asked and it should be a good place for you to start.

Let us know how your research works out for you.