C编程基础:在用gcc编译.c文件后,为什么我看不到.o文件

时间:2021-08-25 13:16:37

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)

我写了一个C程序并用.c扩展名保存。然后我用gcc编译但之后我只看到我的.c文件和.exe文件。该计划运行完美。但是我在理论上学到的.o文件在哪里?是否被覆盖到.exe并且所有这些都是由gcc在步骤中完成的? (预处理,编译,组装和链接)

I'm on a VM running Debian.

我在运行Debian的VM上。

4 个解决方案

#1


2  

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.

默认情况下,gcc在一个步骤中编译和链接。要获取.o文件,您需要编译而不进行链接。这是用-c选项完成的。

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:

如果只需要预处理器的输出,请使用-E选项和-o指定输出文件:

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

#2


1  

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.

在第一个命令之后,你将获得一个.o文件。

#3


1  

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

如果你做了类似gcc test.c之类的东西,那么它只生成可执行文件(为了只编译,请参阅-c选项)

#4


0  

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

以下是使用gcc编译以从C文件创建.o文件的步骤:

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

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

#1


2  

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.

默认情况下,gcc在一个步骤中编译和链接。要获取.o文件,您需要编译而不进行链接。这是用-c选项完成的。

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:

如果只需要预处理器的输出,请使用-E选项和-o指定输出文件:

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

#2


1  

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.

在第一个命令之后,你将获得一个.o文件。

#3


1  

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

如果你做了类似gcc test.c之类的东西,那么它只生成可执行文件(为了只编译,请参阅-c选项)

#4


0  

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

以下是使用gcc编译以从C文件创建.o文件的步骤:

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

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