Marsstar
Marsstar

Reputation: 197

C programming basics: Why can't I see the .o file after I compile my .c file with gcc

I wrote a C programm and saved it with a .c extension. Then I compiled with the gcc but after that I only see my .c file and an .exe file. The program runs perfectly. But where is the .o file that I learned in theory? Has it been overwritten to .exe and all done by the gcc in on step? (Preprocessing, compiling, assembling and linking)

I'm on a VM running Debian.

Upvotes: -1

Views: 1339

Answers (4)

dbush
dbush

Reputation: 224417

By default, gcc compiles and links in one step. To get a .o file, you need to compile without linking. That's done with the -c option.

Suppose you want to compile two files separately, then link them. You would do the following:

gcc -c file1.c      # creates file1.o
gcc -c file2.c      # creates file2.o
gcc -o myexe file1.o file2.o

If you want just the output of the preprocessor, use the -E option along with the -o to specify the output file:

gcc -E file1.c -o file1-pp.c    # creates file1-pp.c

Upvotes: 2

ewcz
ewcz

Reputation: 13097

if you did something like gcc test.c then it produces only the executable file (in order to compile only, see the -c option)

Upvotes: 1

ouah
ouah

Reputation: 145899

Compile and link in two steps:

gcc -Wall -c tst.c
gcc tst.c -o tst

After first command you'll get a .o file.

Upvotes: 1

httpNick
httpNick

Reputation: 2624

here is steps on compiling with gcc to create a .o file from your C file:

http://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html

Upvotes: 0

Related Questions