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 529397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:05:16+00:00 2026-05-13T09:05:16+00:00

I am wondering why gcc/g++ doesn’t have an option to place the generated object

  • 0

I am wondering why gcc/g++ doesn’t have an option to place the generated object files into a specified directory.

For example:

mkdir builddir
mkdir builddir/objdir
cd srcdir

gcc -c file1.c file2.c file3.c **--outdir=**../builddir/objdir

I know that it’s possible to achive this with separate -o options given to the compiler, e.g.:

gcc -c file1.c -o ../builddir/objdir/file1.o
gcc -c file2.c -o ../builddir/objdir/file2.o
gcc -c file3.c -o ../builddir/objdir/file3.o

… and I know that I can write Makefiles via VPATH and vpath directives to simplify this.

But that’s a lot of work in a complex build environment.

I could also use

gcc -c file1.c file2.c file3.c

But when I use this approach my srcdir is full of .o garbage afterwards.

So I think that an option with the semantics of –outdir would be very useful.

What is your opinion?

EDIT: our Makefiles are written in such a way that .o files actually placed into builddir/obj. But I am simply wondering if there might be a better approach.

EDIT: There are several approaches which place the burden to achieve the desired behavior to the build system (aka Make, CMake etc.). But I consider them all as being workarounds for a weakness of gcc (and other compilers too).

  • 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-13T09:05:16+00:00Added an answer on May 13, 2026 at 9:05 am

    This is the chopped down makefile for one of my projects, which compiles the sources in ‘src’ and places the .o files in the directory “obj”. The key bit is the the use of the patsubst() function – see the GNU make manual (which is actually a pretty good read) for details:

    OUT = lib/alib.a
    CC = g++
    ODIR = obj
    SDIR = src
    INC = -Iinc
    
    _OBJS = a_chsrc.o a_csv.o a_enc.o a_env.o a_except.o \
            a_date.o a_range.o a_opsys.o
    OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
    
    
    $(ODIR)/%.o: $(SDIR)/%.cpp 
        $(CC) -c $(INC) -o $@ $< $(CFLAGS) 
    
    $(OUT): $(OBJS) 
        ar rvs $(OUT) $^
    
    .PHONY: clean
    
    clean:
        rm -f $(ODIR)/*.o $(OUT)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.4.4 c89 I am just wondering is it worth passing a const into
gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2) c89 Hello, I am wondering if I
gcc (GCC) 4.6.3 c89 Hello, I am just wondering if this is the best
I have an auto-generated file which looks something like this... static void do_SomeFunc1(void* parameter)
gcc 4.4.4 C89 I am just wondering what most C programmers do when they
I was wondering if it is safe to use the latest GCC version, or
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 c89 Just wondering is there a better way to do
I am using math.h with GCC and GSL. I was wondering how to get
I was wondering how to use GCC on my C source file to dump
I was wondering if there is a GCC C Compiler directive that allows me

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.