GCC 是否合并编译在一起的文件?
Does GCC merge files compiled together?
假设您有 prog.c
,其中包括 lib.h
,其功能在 lib.c
中定义,并且您使用 ̀gcc -O3 lib.c prog.c
.[=16 构建程序=]
GCC 会在编译前合并这两个源文件吗?
GCC 是否能够将 lib.c
的短函数内联到生成的二进制文件中?
答案汇总
这就是诀窍:gcc -flto -O3 lib.c prog.c
。
两个源文件仍然单独编译,但链接器能够将函数从一个文件内联到另一个文件。
Does GCC merge both source files before compiling them?
不,不是
Is GCC able to inline short functions of lib.c into the resulting binary?
是,处于高级优化级别。查看整个程序优化、Link 时间优化和类似选项
假设您有 prog.c
,其中包括 lib.h
,其功能在 lib.c
中定义,并且您使用 ̀gcc -O3 lib.c prog.c
.[=16 构建程序=]
GCC 会在编译前合并这两个源文件吗?
GCC 是否能够将 lib.c
的短函数内联到生成的二进制文件中?
答案汇总
这就是诀窍:gcc -flto -O3 lib.c prog.c
。
两个源文件仍然单独编译,但链接器能够将函数从一个文件内联到另一个文件。
Does GCC merge both source files before compiling them?
不,不是
Is GCC able to inline short functions of lib.c into the resulting binary?
是,处于高级优化级别。查看整个程序优化、Link 时间优化和类似选项