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

猜你喜欢

转载自www.cnblogs.com/Stephen-Qin/p/12718781.html