473,598 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compile a C source file without using the C compiler directly

Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
I tried to compile the fallowing code as fallows
file name: hello.c
# include <stdio.h>

int
main ( void )
{
printf ( "Hello World\n" );

return 0;
}

cpp hello.c hello.i // Preprocessing
cc -S hello.i // Assembly code generating
as -o hello.o hello.s // generate m/c code
ld -o a.out hello.o -lc // linking

In linking phase, I'm getting warning saying that
--
ld: warning: cannot find entry symbol _start; defaulting to 080481a4
--
linking face creates a binary a.out. When i tried to execute it, I'm
getting
--
bash: ./a.out: /usr/lib/libc.so.1: Bad ELF interpreter: No such file
or directory
--

As per the ld man page, we need to link the object file with the
crt0.o and libc, but i didnt find crt0.o in /lib nor in /usr/lib.
Please let me know how to do this.

--
Ganesh

Jun 21 '07 #1
5 3337
ga************* @gmail.com wrote:
Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
Time for some off topic advice - don't do it!

--
Ian Collins.
Jun 21 '07 #2
On Jun 21, 1:23 pm, Ian Collins <ian-n...@hotmail.co mwrote:
ganesh.kunda... @gmail.com wrote:
Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).

Time for some off topic advice - don't do it!

--
Ian Collins.
I just wanted to know how the compiler does all these at one go.

Jun 21 '07 #3
ga************* @gmail.com wrote:
On Jun 21, 1:23 pm, Ian Collins <ian-n...@hotmail.co mwrote:
>ganesh.kunda.. .@gmail.com wrote:
>>Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
Time for some off topic advice - don't do it!
Please don't quote signatures.
>
I just wanted to know how the compiler does all these at one go.
For that you'd have to ask on a platform/compiler specific group.

--
Ian Collins.
Jun 21 '07 #4
"ga************ *@gmail.com" <ga************ *@gmail.comwrit es:
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
[snip]

This is a question about your compiler, not about the C language.

Some compilers may have an option to display the steps it goes through
to compile and link your code. Consult your compiler's documentation.

<OT>If you're using gcc, try the "-v" option; "info gcc" for
details.</OT>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 21 '07 #5
In article <11************ **********@j4g2 000prf.googlegr oups.com>,
"ga************ *@gmail.com" <ga************ *@gmail.comwrit es
>Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
>cpp hello.c hello.i // Preprocessing
cc -S hello.i // Assembly code generating
as -o hello.o hello.s // generate m/c code
ld -o a.out hello.o -lc // linking
This is compiler specific. However all C compilers generally follow the
same steps.

Incidentally at one time compilers used to be 3 pass so your cc step
would have been
cc1
cc2
cc3

what has happened over the years is the three parts of the compiler have
been merged into one and in most the pre-processor as well.

They used to be separate because there was not enough memory etc to do
the whole lot at once and floppy disks held 360K (what hard disk?) . A
compiler/assembler/linker might be on three separate floppies.

These days the compiler will be able to "store" the temp files in memory
or quickly on the hard disk. Also the whole compiler can be called from
hard disk without having to swap floppies.

Many compilers are now "single pass" with the CPP and turn our object
code completely missing the assembler phase. So you would have
cc
ld

For your question MAKE was invented.

You call MAKE with a make file.

You have to write the makefile yourself, just the once and in future it
will call the compiler parts and the appropriate files.

Otherwise you could use a batch file or script. (This is al very basic
stuff)

Modern compiler suites use an IDE and that hides the makefile (or does
it's own similar thing) and compiler but under the covers it too calls
the compiler, linker assembler as above. Though in some compiler suites
they will be DLL's rather than stand alone exe programs with a command
line.

However you should have covered this in your initial programming
classes.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 21 '07 #6

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

Similar topics

188
8357
by: Ilias Lazaridis | last post by:
I'm a newcomer to python: - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python 2.4 installer for windows. Now I have problems to compile python extension that some packages
2
2444
by: Sean Dettrick | last post by:
I am wondering if it is possible to increment an integer at compile time using template<int N> (or by any other method, e.g. compiler directives etc), across multiple source files. This may sound crazy, but I wish to build a string array (which requires no user maintenance) of source file RCS version numbers! The idea is, I would like to be print the beggers out or operate on them at run time if I feel like it, by using a (maintenance...
5
2134
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator=' in '*this = CTest::operator+(CTest&)((+t2))' test2.cpp:49: error: candidates are: CTest CTest::operator=(CTest&) make: *** Error 1
5
3316
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new rightType;
10
4440
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After creating an instance, starting the database, creating a database, and entering the table definitions, all of which seems to work OK, I entered a tiny 8-row table and can do...
7
4493
by: Holger (David) Wagner | last post by:
Hi Group, I've searched the Web for precompilers that compile ASPX/ASCX pages just like it can be done with JSPs, but so far, I've only found approaches targetted at increasing the performance. What I'd like to do this for, however, is discovering compile-time errors during my normal build. Currently, just a typo in a Property name goes unnoticed until the page is hit the first time which is not particularly satisfying (this is like...
5
5363
by: DFB | last post by:
I am the author of the ZLibNetWrapper project on SourceForge (located at zlibnetwrapper.sf.net). This project is a simple mixed-mode .NET wrapper around the ZLib compression library. The ZLib code consists of a few C source files. For Visual Studio 2003, this wrapper compiled fine without having to change any of the ZLib source. However, according to "Breaking Changes in the Visual C++ 2005 Compiler" (at...
66
7434
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it, including the BCL, ASP.NET and LINQ) available both for viewing and debugging into. I won't go into all the details here, as they're covered on Scott Guthrie's blog:
11
1756
by: Tim H | last post by:
The following program compiles just fine in C, but not in C++. Can anyone explain why? I have a chunk of code that defines stuff like this in headers (without the extern) that I can not easily change. The C compiler recognizes the first foo and second foo as the same. The C++ compiler not so much. Is there a way to get this to compile in C++ without changing all the headers?
0
7899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8050
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.