473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

compilation process

Hi!

I have a few questions about compilation of C programs.
What does the compiler do after I send him preprocessed file and what
happens from then on? What does the linker do ? Do the libraries contain
C-code, or are they in a binray form?
For exapmle, when I'm compiling a simple program on linux, and I use
sqrt, can I only write #include <math.h>, or do I have to link against
math library too, gcc myprog.c -o myprog -lm ? I'm not quite clear with
this, so any comments and answers are welcome, tutorials and HOW-TOs, or
anything like that is welcome.

Thanks in advance

Davor

Nov 13 '05 #1
3 5228
Davor <da*********@yahoo.com> scribbled the following:
Hi! I have a few questions about compilation of C programs.
What does the compiler do after I send him preprocessed file and what
happens from then on? What does the linker do ? Do the libraries contain
C-code, or are they in a binray form?
Implementation-defined. Usually they are in binary form.
For exapmle, when I'm compiling a simple program on linux, and I use
sqrt, can I only write #include <math.h>, or do I have to link against
math library too, gcc myprog.c -o myprog -lm ? I'm not quite clear with
this, so any comments and answers are welcome, tutorials and HOW-TOs, or
anything like that is welcome.


It is generally NOT enough to #include <math.h>. Including headers only
tells the compiler how to CALL the functions defined in the library. It
doesn't tell anything about the actual CODE in the functions. With gcc,
you have to use the -lm switch.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Products like that make me wish I could menstruate."
- Andy Richter
Nov 13 '05 #2
In 'comp.lang.c', Davor <da*********@yahoo.com> wrote:
I have a few questions about compilation of C programs.
Most of them are off-topic...
What does the compiler do after I send him preprocessed file and what
happens from then on?
It translates the C-source into machine code. Actually, it does its best, but
some addresses are left (and noted) 'unresolved'.
What does the linker do ?
It tries so solve the unrersolved addresses.
Do the libraries contain
C-code, or are they in a binray form?
Binary.
For exapmle, when I'm compiling a simple program on linux, and I use
sqrt, can I only write #include <math.h>, or do I have to link against
math library too, gcc myprog.c -o myprog -lm ?
Yes, you have to link the math library. The headers only include the
prototypes and some constants and types definitions. The executable code is
in the library.
I'm not quite clear with
this, so any comments and answers are welcome, tutorials and HOW-TOs, or
anything like that is welcome.


www.google.com is your friend.

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #3
On Sun, 14 Sep 2003 21:03:51 +0200, Davor <da*********@yahoo.com>
wrote in comp.lang.c:
Hi!

I have a few questions about compilation of C programs.
The C standard defines eight phases of translation. They are very
specific, but are relatively high level. They are not actually
required to be performed step-by-step, it is quite possible for a
compiler to combine several together as long as the results are the
same.
What does the compiler do after I send him preprocessed file and what
happens from then on? What does the linker do ? Do the libraries contain
C-code, or are they in a binray form?
These details are not specified by the C standard. Things like object
and executable file formats, linkers, and how libraries are managed
are very specific to the operating system and compiler you use. The
standard specifies what the results must be, not the individual
intermediate details.
For exapmle, when I'm compiling a simple program on linux, and I use
sqrt, can I only write #include <math.h>, or do I have to link against
math library too, gcc myprog.c -o myprog -lm ? I'm not quite clear with
this, so any comments and answers are welcome, tutorials and HOW-TOs, or
anything like that is welcome.

Thanks in advance

Davor


The last part, about needing to manually link the math library with
most UNIX/Linux compilers, is basically a left-over annoyance that has
been inexcusable for the at least the last 10 years. But that is also
something specific to the tool set you are using.

There are draft copies of the current C standard in several formats
available at http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n869/,
where you can read about the high level phases of translation the
language defines.

If you want more details on how gcc or any other specific compiler
actually performs its work, you need to take the question to a support
group for that particular compiler.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
5
by: Roman Ziak | last post by:
Hello, I posted this message to comp.compilers couple days ago, but it did not apear there for some reason. --- I have had this idea about the compilation process, but I may be not sound...
2
by: FireStarter | last post by:
Guys, in the code that follows, why does the method F() still compile, even if DBG is undefined? Inside method G(), the code inside <#if DBG> does not compile (notice that I can write whatever I...
1
by: Krissy | last post by:
Hi all, Sometimes after building a project, or uploading it to the server, when we go to view the page, we get the following error. To overcome this we have to end the aspnet_wp.exe process...
5
by: Scott | last post by:
So I can't figure out how to Google for this problem, I'll try asking for a solution here. Whenever I deploy changes, whether they are changed code-behind DLL's or ASPX/ASCX/ASAX pages to my...
6
by: Jéjé | last post by:
Hi, hoew can I improve the compilation process of a sharepoint website? my server is: 2 * P3 Xeom 1ghz 4go ram 2 * 36gb (mirror for OS and website) 2 * 36 Raid 0 (stripping; for temp files...
0
by: Sin | last post by:
> Xxxxx : error PRJ0008 : Could not delete file 'd:\xxxxxxx.dll'. > Make sure that the file is not open by another process and is not write-protected. > > LINK : fatal error LNK1168: cannot open...
5
by: Stuart Carnie | last post by:
I suspect it's unlikely, but you'll never know until you ask, but are there any attributes that would allow us to contribute to the compiled output? e.g. // this class exists in a separate,...
6
by: maxwell | last post by:
I'm trying to use the gpp utility (Gnu points to http://en.nothingisreal.com/wiki/GPP) to do conditional compilation in Python, and I'm running into a problem: the same '#' character introduces...
2
by: f0zzyNUE | last post by:
hi everyone, currently we are testing the performance our application (asp.net based CMS) ... for that reason we wrote a "spider" that starts webrequests for all relevant pages which results in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.