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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:06:14+00:00 2026-06-09T06:06:14+00:00

The following is the Makefile i use. All is well, except for .o should

  • 0

The following is the Makefile i use. All is well, except for .o should be created in obj/ directory and it’s not.

What am i doing wrong please?

enter image description here

After making sure that

  • src directory contains a.cpp
  • target directory exists and is empty
  • obj directory exists and is empty

When make is ran, i see

g++ -pedantic -Wall -c src/a.cpp  -o /Users/me/Dropbox/dev/c++/hott/obj/src/a.o

when it should be

g++ -pedantic -Wall -c src/a.cpp  -o /Users/me/Dropbox/dev/c++/hott/obj/a.o

What am i doing wrong please?

UPDATE: Nothing seems to change when hardcoding path and not relying on pwd resolution

  • 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-06-09T06:06:15+00:00Added an answer on June 9, 2026 at 6:06 am

    If you use -o you have to specify the filename, not just the output path. Try:

    $(CC) $(FLAGS) $(SOURCES) $(OBJ)/$@
    

    This question may help, too:

    • What do the makefile symbols $@ and $< mean?

    Also, you may want to call FLAGS something like CFLAGS, meaning “the flags for compilation”.


    Edit

    Note that you are not using make efficiently, because you are always recompiling all your .o files from your .cpp files. You should instead use a Pattern Rule, so that Make can have rules to only build what is necessary. (ie. “To build any .o file from a .cpp file, do this: ___”) 

    %.o : %.c
        $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    

    You could edit this to include $(OBJ) before the $@.

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

Sidebar

Related Questions

If I use socket.makefile and then close the file object as well as the
I have the following makefile that I use to build a program (a kernel,
I use following find command to find and show all files having the input
I have a Makefile with the following: AVAR= all : if [ -d ../old
I have the following makefile for my project, and I'd like to configure it
Utility: NMake Platform : Windows 7 I have the following Makefile FILE = $(shell)
I have the following implicit rule in a makefile: a1 b1: %: %.o On
I found the following lines in a makefile tutorial, but I have some problem
I have the following PHONY target in Makefile install: echo /usr/bin/shelldecrypt must be writable
I have a makefile with something like the following targets: install: do a whole

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.