473,698 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object files

JS
I am a bit confused about the meaning of object files (.o).

I read this in a make file:

lotto: main.o init.o select.o sort.o display.o
gcc main.o init.o select.o sort.o display.o -o lotto

main.o: main.c lotto.h
gcc -c main.c

....etc.

Why does the code that I write in main.c suddenly become a .o file?
Nov 14 '05 #1
11 2916
M.I
The followoing line tells make to compile your main.c file into main.o.

main.o: main.c lotto.h
gcc -c main.c
..c file are source files in human reabable form, whereas .o file
contains the instruction for linker which creates an executable file
out of object file, .o file is not close to human readable form. Also
if you have some code that you want to share or sell but you don't want
the client to see your source code you can give them .o files.

Nov 14 '05 #2
JS a écrit :
I am a bit confused about the meaning of object files (.o).

I read this in a make file:

lotto: main.o init.o select.o sort.o display.o
gcc main.o init.o select.o sort.o display.o -o lotto

main.o: main.c lotto.h
gcc -c main.c

...etc.

Why does the code that I write in main.c suddenly become a .o file?


These are temporary files that are not linked together.
I don't really know how to explain that...
These files are not executable, they contain the compiled code of the .c
file.
The compiler, first : make the binary code for each .c file and then :
put all these parts together to make a real executable.

This allows the developer to proceed in several parts/files (in a
development team, for example)

When you have few files, for example a main.c, you can compile and link
it directy by using : gcc main.c -o main

--
Salutations,

Joachim Naulet

06 14 90 06 21
http://jnaulet.no-ip.com
Nov 14 '05 #3
M.I wrote:
The followoing line tells make to compile your main.c file into main.o.

main.o: main.c lotto.h
gcc -c main.c
.c file are source files in human reabable form, whereas .o file
contains the instruction for linker which creates an executable file
out of object file, .o file is not close to human readable form. Also
if you have some code that you want to share or sell but you don't want
the client to see your source code you can give them .o files.


You can't give anybody a '.o' file. The '.o' file is an output
that depends on the brand of compiler you use. One compiler's
object file may not be compatible with another brand of compiler,
linker or another version of the same compiler.

What's worse is that the object file may not be portable across
platforms either.

Before you recommend sharing of '.o' files, please have more
information ready or state the warning.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Nov 14 '05 #4
JS wrote:
I am a bit confused about the meaning of object files (.o).

I read this in a make file:

lotto: main.o init.o select.o sort.o display.o
gcc main.o init.o select.o sort.o display.o -o lotto

main.o: main.c lotto.h
gcc -c main.c

...etc.

Why does the code that I write in main.c suddenly become a .o file?


Object files, not a topic of this newsgroup, are an output
from a compiler (translator).

Some compilers can create executables directly from
source code. Other compilers create intermediate files
known as "object" files (with common extensions of '.o'
or '.obj'). The object files must be linked together
to form an executable.

One rationale about using object files is to reduce
the time building a program. In general, object files
are faster to process than translating source code.
If the source for the object file has not changed,
there is no need to compile the source again, thus
saving build time.

A common tool used to track and process these
dependencies (i.e. executable depends on one or
more objects; object depends on one or more
source files; source depends on zero or more
headers) is called "Make" and its instructions
are in a "makefile". Both of which are off-topic
in this newsgroup. Basically, if the dependency
is newer than the target, the target is recreated
from the dependency.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Nov 14 '05 #5
Thomas Matthews wrote:
M.I wrote:
.c file are source files in human reabable form, whereas
.o file contains the instruction for linker which creates
an executable file out of object file, .o file is not close
to human readable form. Also if you have some code that you
want to share or sell but you don't want the client to see
your source code you can give them .o files.


You can't give anybody a '.o' file. The '.o' file is an output
that depends on the brand of compiler you use. One compiler's
object file may not be compatible with another brand of compiler,
linker or another version of the same compiler.

Before you recommend sharing of '.o' files, please have more
information ready or state the warning.


Some compiler vendors make an effort to have a common ABI and
interchangeable object files. You should consult the compiler
documentation to determine if distributing code via static
libraries is going to work. (A static library is merely zero
or more object files stored one after the other in a single
file). For example, GCC's linker is capable of reading just
about any compiler's object files, via the GNU libBFD library.

It's not unheard of for software to be distributed as .lib
or .a files.

Nov 14 '05 #6
On Wed, 13 Apr 2005 20:50:36 GMT, Thomas Matthews
<Th************ *************@s bcglobal.net> wrote:
You can't give anybody a '.o' file.
Put floppy disk in computer.
Copy *.o to floppy disk.
Take floppy disk out of computer, give it to someone.

I've just given someone a load of .o files.

"You can't give anybody a '.o' file" is just plain untrue.
The '.o' file is an output that depends on the brand of compiler you
use. One compiler's object file may not be compatible with another
brand of compiler, linker or another version of the same compiler.
Which century are you in? That may have been true 20 years ago, but
these days we have stardards for such things.

It is very common in the commercial world to do "binary releases"
of software in object or library (collection of object files) form, to
protect the source, all you have to do is to make sure that you compile
them with compatible software to that of the person using them.

In practice, most compilers in the Windows world produce compatible
object files at least for C (C++ name mangling is a different matter),
and they do for a single platform in the Unix world as well. How do you
think standard libraries work? On my Debian GNU/Linux system I have
dozens (at least) of libraries supplied in object form, they don't need
recompiling if I install a new version of the compiler (or even another
compiler on that system). Even Gentoo, which is a GNU/Linux
distribution where almost everything is compiled from source by the
installer, distributes object files and libraries of object files to get
started (to build an application you need to have the standard libraries
and object files first before you can compile it).

It's called "binary compatibility", and is something compiler and
library writers spend a lot of time making sure that they get right so
that people don't have to build everything from source all the time.
What's worse is that the object file may not be portable across
platforms either.
So you produce them for the appropriate platform. At work we produce
object files for Windows, GNU/Linux-x86 and ARM (which has a published
standard ABI) for distribution, you are given (sold) the version
appropriate for your use. If we had customers who used other systems we
would produce the object files for those as well (we might charge a
'setup' fee if it meant us buying extra hardware or software to produce
them).
Before you recommend sharing of '.o' files, please have more
information ready or state the warning.


How would you go about giving someone code for them to use but they
aren't allowed to see?

Chris C
Nov 14 '05 #7
On Wed, 13 Apr 2005 21:33:12 +0200, in comp.lang.c , JS
<d4***@44ada.co m> wrote:

(reordered slightly)
Why does the code that I write in main.c suddenly become a .o file?
because you compiled it to an object. This is typically a
machine-language set of instructions which represent your code. After
its been compiled, most systems require it to also be linked with
libraries of other objects, to form a complete executable. These other
objects contain machine instructions for stuff like disk io. screen
interaction and so on.
I read this in a make file:


'make' is a tool to automate the compilation and linking process.
Unfortunately its also offtopic here, as its platform-specific and
different make tools work differently. I believe you're on linux or
unix so comp.unix,progr amming is probably a good place to dsicuss it.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #8
In article <sl************ ******@ccserver .keris.net>,
Chris Croughton <ch***@keristor .net> wrote:
On Wed, 13 Apr 2005 20:50:36 GMT, Thomas Matthews
<Th************ *************@s bcglobal.net> wrote:
The '.o' file is an output that depends on the brand of compiler you
use. One compiler's object file may not be compatible with another
brand of compiler, linker or another version of the same compiler.

Which century are you in? That may have been true 20 years ago, but
these days we have stardards for such things.


In this group, it is common to use colourful expressions such as
"nose demons" with respect to undefined behaviour (no matter how
commonly implemented.)

*Someone* may have standards for formats such as ELF and COFF,
but it isn't the ISO or ANSI subgroups that produced the specification
for C.

This group often touches upon unusual behaviours that can occur
on embedded systems, systems with unusual numbers of bits per
register, and other sports of nature that are none-the-less
compatible with the C standard.

All parts of Thomas's statement have happened to me, and it was
certainly less than 20 years ago.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Nov 14 '05 #9
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
[...]
Did Thomas say that you can't distribute object files or executables?

Re-read what he said: he said that some things *might* not be
compatible with other apparently similar things. If you do happen
to get compatibility, that's a bonus. But it doesn't fall within
the scope of the C standard and thus is not something that someone
trying to write portable C should count on.


Thomas also said:

] You can't give anybody a '.o' file.

though I think that was just a fairly harmless overstatement.

--
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.
Nov 14 '05 #10

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

Similar topics

15
2278
by: Ville Vainio | last post by:
Pythonic Nirvana - towards a true Object Oriented Environment ============================================================= IPython (by Francois Pinard) recently (next release - changes are still in CVS) got the basic abilities of a system shell (like bash). Actually, using it as a shell is rather comfortable. This all made me think... Why do we write simple scripts to do simple things? Why do we serialize data to flat text files in...
2
1840
by: Kenneth McDonald | last post by:
I'd like to propose a new PEP , for a standard library module that deals with files and file paths in an object oriented manner. I believe this module should be included as part of the standard Python distribution. Background ========== Some time ago, I wrote such a module for myself, and have found it extremely useful. Recently, I found a reference to a similar module, http://www.jorendorff.com/articles/python/path/ by Jeff Orendorff.
1
3933
by: Patrick | last post by:
Hi all, New to .NET, I'm working on an Winforms client application using VS 2005 beta2. My needs considering data storage are the followings: (1) Small files (0 < length < 10 mb), containing lots of small 'objects' that need to be loaded into memory at runtime, in order to garantee small access time to each 'object'. Each of these 'objects' collection should be able to easily bind to a DataGridView, AND to provide *filtering* and...
0
1164
by: IanT | last post by:
Hi I'm using Visual C++ .net I'm getting the linker error that one of my object files cant be found It seems that my compiler isnt producing .obj files (or at least not putting them in the debug folder) I've done a harddrive search for the .obj file and it seems that its not being produced at all. Infact the compiler doesnt seem to be producing any object files, but its not giving an error untill I get to linking. Any ideas why there are no...
9
3918
by: kermit | last post by:
I keep seeing that you can use the FileSystemObject in either VB script, or Javascript on an aspx page. I added a refrence to the scrrun.dll I added importing namespaces for 'System.Object', 'Scripting', 'Scripting.FileSystemObject', and a few others However, when I try to create the fso object I keep receiving an error. 'ActiveX component can't create object: 'Scripting.FileSystemObject'
2
3548
by: avanhalen | last post by:
To embed flash objects in my pages, I read them from a database. A script file (Filedownload.aspx) reads it from the database, and streams it to the browser. Here are two example flash objects in a page. The first 1 (a simple link to an existing swf-file on the webserver) is showing in each browser (IE & FF), while the other one (using the filedownload page) is only being shown in FF. Does it have something to do with file-extension?
19
4649
by: Alan Carpenter | last post by:
Access 8 on Win98 and WinXP I'm having trouble with wildcards in the .Filename property of the FileSearch Object giving different results on win98 and XP. I've been successfully using FileSearch in win98 to fill an array with filenames with no problems since about 1998. From the 97 Help: (The Filename Property of the FileSearch object) --------------------------
4
6283
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dInfo As DirectoryInfo dInfo = New DirectoryInfo(Server.MapPath("/Folder1")) dgFD.DataSource = dInfo.GetFiles("*.*") dgFD.DataBind() End Sub
1
2075
by: kgk | last post by:
I would like to concatenate several file-like objects to create a single file-like object. I've looked at fileinput, however this returns a fileinput object that is not very file-like. something like # a has 50 bytes, and b has 100 bytes f = FileList (open('a'), open('b')) f.read (100) # read 50 bytes from a and 50 from b
0
8612
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
9032
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...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
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
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.