[英]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.我写了一个 C 程序并用 .c 扩展名保存它。 Then I compiled with the gcc but after that I only see my .c file and an .exe file.
然后我用 gcc 编译但之后我只看到我的 .c 文件和一个 .exe 文件。 The program runs perfectly.
程序运行完美。 But where is the .o file that I learned in theory?
但是我从理论上学到的.o文件在哪里? Has it been overwritten to .exe and all done by the gcc in on step?
它是否已被覆盖为 .exe 并且所有步骤都由 gcc 完成? (Preprocessing, compiling, assembling and linking)
(预处理、编译、组装和链接)
I'm on a VM running Debian.我在运行 Debian 的虚拟机上。
By default, gcc
compiles and links in one step.默认情况下,
gcc
一步编译和链接。 To get a .o
file, you need to compile without linking.要获得
.o
文件,您需要在不链接的情况下进行编译。 That's done with the -c
option.这是通过
-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
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
文件。
如果你做了类似gcc test.c
事情,那么它只生成可执行文件(为了只编译,请参阅-c
选项)
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.