Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:16:22+00:00 2026-05-26T20:16:22+00:00

I have many source files in source directory. For example a.c, b.c, c.c and

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:16:23+00:00Added an answer on May 26, 2026 at 8:16 pm

    Use add_custom_target/add_custom_command.

    In any way it is non-portable construction, so here simple example

    [project root] with two folders in it [src] – here N files, [build] for binary, and CMakeLists.txt

    cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
    set(TARGET_NAME whole)
    project(${TARGET_NAME} C)
    
    file(GLOB SRC_FILES src/*.c)
    
    add_custom_target(${TARGET_NAME} ${CMAKE_C_COMPILER} -flto -fwhole-program ${SRC_FILES} -o ${TARGET_NAME})
    

    In build folder run cmake ..; make VERBOSE=1 whole

    This will make the work for you.

    But, -fwhole-program work only with executable, as per documentation.

    -fwhole-program
    Assume that the current compilation unit represents the whole program being compiled. All public functions and variables with the exception of main and those merged by attribute externally_visible become static functions and in effect are optimized more aggressively by interprocedural optimizers.

    So you mast have main defined anywhere in your source files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen simple example Ajax source codes in many online tutorials. What I
I have many large files under project/public/deploy/. All the rest is my source codes.
Situation: I have many gzipped input files that I want to process in a
I have a folder with many source code files. I would like to find
I have many Java source files which I need to change their package line
Let's say I have a source file with many preprocessor directives. Is it possible
Contributing to open source can have many forms: working with issue trackers, patches, further
I have many items inside a list control. I want each item to have
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
Now I have two directory, all of header files *.h are included in directory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.