Questions tagged [object-files]

An object file is the real output from the compilation phase.

An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)

A linker takes all these object files and combines them to form one executable (assuming that it can, ie: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)

293 questions
198
votes
5 answers

What's an object file in C?

I am reading about libraries in C but I have not yet found an explanation on what an object file is. What's the real difference between any other compiled file and an object file? I would be glad if someone could explain in human language.
Pithikos
  • 18,827
  • 15
  • 113
  • 136
109
votes
5 answers

How to view symbols in object files?

How can I view symbols in a .o file? nm does not work for me. I use g++/linux.
nakiya
  • 14,063
  • 21
  • 79
  • 118
98
votes
2 answers

combine two GCC compiled .o object files into a third .o file

How does one combine two GCC compiled .o object files into a third .o file? $ gcc -c a.c -o a.o $ gcc -c b.c -o b.o $ ??? a.o b.o -o c.o $ gcc c.o other.o -o executable If you have access to the source files the -combine GCC flag will merge the…
Lucian Adrian Grijincu
  • 2,491
  • 2
  • 18
  • 18
71
votes
5 answers

Contents of a static library

I have a static library, say mystaticlib.a. I want to see its contents, such as the number of object files inside it. How can I do this on gcc?
Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
60
votes
8 answers

What does an object file contain?

During the various stages of compilation in C or C++, I know that an object file gets generated (i.e., any_name.o file). What does this .o file contain? I can't open it since it's a binary file. Could anybody please help me? Are the contents of the…
Vijay
  • 65,327
  • 90
  • 227
  • 319
39
votes
2 answers

Relation between object file and shared object file

what is the relation between shared object(.so) file and object(.o) file? can you please explain via example?
ASHOK
  • 1,475
  • 4
  • 14
  • 14
36
votes
5 answers

Why Compile to an Object File First?

In the last year I've started programming in Fortran working at a research university. Most of my prior experience is in web languages like PHP or old ASP, so I'm a newbie to compile statements. I have two different code I'm modifying. One has an…
tomshafer
  • 795
  • 3
  • 8
  • 12
36
votes
4 answers

expected unqualified-id before string constant

I'm currently writing a C++ application which implements an Oscillator in conjuction with math.h. The code I have should work fine for the application (trying to compile an object file), bu I'm getting a compiler error most likely having to do with…
DanMoore
  • 621
  • 1
  • 8
  • 14
32
votes
2 answers

What is the difference between .LIB and .OBJ files? (Visual Studio C++)

I know .OBJ is the result of compiling a unit of compilation and .LIB is a static library that can be created from several .OBJ, but this difference seems to be only in the number of units of compilation. Is there any other difference? Is it the…
31
votes
4 answers

What is "object" in "object file" and why is it called this way?

I was asked a question: "What is an 'object file'?". After looking at Wiki, I only know that it contains objects. But what are those objects and why someone called them that way?
sthlm58
  • 1,142
  • 1
  • 9
  • 28
21
votes
2 answers

Incremental linking using gcc on linux. Is it possible?

The way my team's project is developed, we generate a Shared Object library for our application from all all of our .o object files. My task (hopefully it is specific enough but also general enough to be of use to others!) is to link in only the…
Raphael Raven
  • 213
  • 2
  • 5
20
votes
3 answers

How do I produce only an object file (*.o) from a CMake build target?

I'm trying to build an object file using CMake, but I can't seem to get CMake to build something other than a complete executable. I'm basically looking for the result of the following compilation (the result will be loaded on a VxWorks target and…
Nick
  • 201
  • 1
  • 2
  • 3
19
votes
2 answers

How to put generated files (e.g. object files) into a separate folder when using Qt/qmake?

I have a Qt project that uses qmake. To improve clarity and readability, I'd like to keep the source files build system generated files (such as object files) separate. So my first step was putting the source files into a src/ sub…
vog
  • 23,517
  • 11
  • 59
  • 75
16
votes
1 answer

Translation unit vs Compilation unit vs object file vs executable vs.... in C++

I couldn't find the difference between translation unit, compilation unit, object file, executable...At many places I've seen that one is used instead of other. I am aware that these files are generated during C++ program compilation and linkage.…
pasha
  • 2,035
  • 20
  • 34
14
votes
3 answers

It is possible to read an object file?

I was curious about .obj files: I pretty much don't know what they are (or what they contain), so I opened them with Vim text editor and what I found inside was an Alien like language... Is there any way to understand what they represent and what is…
Leandro
  • 183
  • 1
  • 2
  • 10
1
2 3
19 20