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

  • Home
  • SEARCH
  • 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 825213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:13:10+00:00 2026-05-15T03:13:10+00:00

How does one combine two GCC compiled .o object files into a third .o

  • 0

How does one combine two GCC compiled .o object files into a third .o file?

$ gcc -c  a.c -o a.o
$ gcc -c  b.c -o b.o
$ ??? a.o b.o -o c.o
$ gcc c.o other.o -o executable

If you have access to the source files the -combine GCC flag will merge the source files before compilation:

$ gcc -c -combine a.c b.c -o c.o

However this only works for source files, and GCC does not accept .o files as input for this command.

Normally, linking .o files does not work properly, as you cannot use the output of the linker as input for it. The result is a shared library and is not linked statically into the resulting executable.

$ gcc -shared a.o b.o -o c.o
$ gcc c.o other.o -o executable
$ ./executable
./executable: error while loading shared libraries: c.o: cannot open shared object file: No such file or directory
$ file c.o
c.o: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped
$ file a.o
a.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
  • 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-15T03:13:10+00:00Added an answer on May 15, 2026 at 3:13 am

    Passing -relocatable or -r to ld will create an object that is suitable as input of ld.

    $ ld -relocatable a.o b.o -o c.o
    $ gcc c.o other.o -o executable
    $ ./executable
    

    The generated file is of the same type as the original .o files.

    $ file a.o
    a.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
    $ file c.o
    c.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
    

    For an in-depth explanation see MaskRay’s Relocatable linking article.

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

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would like to know (...) if my approach for… May 16, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer You want merge replication. May 16, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer The fastest way to done here may be to just… May 16, 2026 at 5:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two .htaccess files that I need to combine into one. The first
I have a scenario where I combine two tables into one (using UNION) and
I am currently trying to combine two collections into one for binding to a
I have a class split across two files. One of these is generated, the
I have two XML docs that I've created and I want to combine these
I have two nearly identical javascript functions that are used to initiate a jquery
I'm reading data from a file into a vector of strings called data .
As a long time World of Warcraft player, and a passionate developer I have
After considering the answers to my previous question ( One SVN Repository or many?
I have a relatively simple (I think) use-case but I can't find any examples

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.