Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

c - Running gcc's steps manually, compiling, assembling, linking

If you have a simple C program, like

int main(void) {return 0;}

It can be compiled with gcc -o test test.c.

As I understand, gcc performs compiling, assembling then linking. The latter two steps are achieved by it running as and ld.

I can generate the assembly code by using gcc -S test.c.

What would you type into a terminal, to convert the assembly code into an executable?

(the reason for doing so is to learn assembly)

question from:https://stackoverflow.com/questions/8527743/running-gccs-steps-manually-compiling-assembling-linking

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

These are the different stages using gcc

gcc -E  --> Preprocessor, but don't compile
gcc -S  --> Compile but don't assemble
gcc -c  --> Preprocess, compile, and assemble, but don't link
gcc with no switch will link your object files and generate the executable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...