简体   繁体   中英

how to compile c/cpp code in such a way that it gives preprocessed assembled and object file after compilation in linux?

if source file is source.cpp then compiler output should have source.i source.s source.o in my directory not only .o file.

where

  1. preprocessed = source.i
  2. assembly = source.s
  3. object = source.o

i know first two files are being created but later on they got deleted only .o file is shown so that linker can link object file but i want to see those two files also.

for linux any flag or something?.

According to the gcc man pages

-save-temps -save-temps=cwd Store the usual "temporary" intermediate files permanently; place them in the current directory and name them based on the source file. Thus, compiling foo.c with -c -save-temps would produce files foo.i and foo.s, as well as foo.o. This creates a preprocessed foo.i output file even though the compiler now normally uses an integrated preprocessor.

so you should compile your code like this

g++ -save-temps source.cpp

You can create individual file for each stage of compiler.

Preprocessor : g++ -E file.cpp -o file.i

Translator : g++ -S file.i -o file.s

Assembler : g++ -c file.s -o file.o

linker : g++ file.o -o file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM