1. 程式人生 >實用技巧 >其它 >gcc -o選項:指定輸出檔案

gcc -o選項:指定輸出檔案


使用格式: [infile] -o [outfile]

[infile] 可以是原始檔, 目標檔案或者彙編檔案;[outfile]可以是目標檔案,可執行檔案,預處理檔案

其中[infile]和[outfile]可以是一個檔案,也可以是一組檔案.

如果不使用 -o 選項,那麼將採用預設的輸出檔案

1.當[infile]為原始檔,[outfile]為可執行檔案時:

gcc fun1.c main.c -o app.out

當沒有-o app.out時,預設輸出為a.out

2.當[infile]為原始檔,[outfile]為目標檔案時,即只編譯:

gcc -c fun1.c -o f.o  #需要有-c,它表示只編譯

當沒有-o f.o時,輸出為fun1.o.

3.當[infile]為原始檔,[outfile]為預處理檔案時,

gcc -E fun1.c -o fun1.i

4.當[infile]為目標檔案,[outfile]為可執行時,即連結:

gcc -c fun1.c main.c #只編譯

gcc fun1.o main.o -o app.out