How do you get assembler output from C/C++ source in gcc?

后端 未结 17 1809
天命终不由人
天命终不由人 2020-11-22 02:43

How does one do this?

If I want to analyze how something is getting compiled, how would I get the emitted assembly code?

17条回答
  •  悲哀的现实
    2020-11-22 03:09

    Here is a solution for C using gcc :

    gcc -S program.c && gcc program.c -o output
    
    1. Here the first part stores the assembly output of the program in the same file name as Program but with a changed .s extension, you can open it as any normal text file.

    2. The second part here compiles your program for actual usage and generates an executable for your Program with a specified file name.

    The program.c used above is the name of your program and output is the name of the executable you want to generate.

    BTW It's my First post on StackOverFlow :-}

提交回复
热议问题