I have many source files in source directory. For example a.c, b.c, c.c and want to compile it by gcc with -combine option.
set(CMAKE_C_FLAGS "-combine")
set(SRC a.c b.c c.c)
add_executable(a.out ${SRC})
Cmake compiles each *.c file in object file, but I want to compile all sources to one object. How can I get this.
In terms of gcc:
gcc -combine a.c b.c c.c -o module.o
ar rcs library.a module.o
But cmake uses per-module translation of sources.
gcc a.c -o a.o
gcc b.c -o b.o
gcc c.c -o c.o
ar rcs library.a a.o b.o c.o
Translation with combine could speed up performance of program. I couldn't use LTO which could resolve the same problem in cmake due to old version of gcc.
Thanks.
-combine
exists? I have a feeling that that's not what you're trying to do. Maybe you mean-fwhole-program
, which is morally equivalent to concatenating all your source files together. But more likely you're just trying to make a reusable library. Use-shared
to make a dynamic library, or just use thear
program to combine lots of.o
files into a static library. CMake can automate both for you.-fwhole-program
?