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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:05:48+00:00 2026-05-12T10:05:48+00:00

I have a directory called project . It contains two sub-directories called client and

  • 0

I have a directory called project.

It contains two sub-directories called client and server, and a makefile called Makefile.

client and server have got source files called client.c and server.c, respectively.

I don’t have any separate makefiles in the subdirectories for sources belonging to that directory. All builds are done by the single makefile. The Makefile code is

FLAGS = -W -Wall -g -pthread

SERV =./server/server.c      #My server code 
CLI =./client/client.c       #My client code

build:svr cnt

svr: $(SERV) 
    cc $(FLAGS) $(SERV) -o ./server/server.out
cnt: $(CLI)
    cc $(FLAGS) $(CLI) -o ./client/client.out

Now I ran make cnt and it replied

cc -W -Wall -g -pthread ./client/client.c -o ./client/client.out

The problem is all the subsequent make cnt commands end up compiling it again and outputting the above text even though I’m not changing ./client/client.c

I’m stuck here. Don’t know what to do.

What I want to do is:

  • With make cnt, compile client/client.c and output its executable in the client/ directory
  • With make svr, compile server/server.c and output its executable in server/ directory.
  • And with make, compile bothserver/server.candclient/client.c` and output their executables in their respective directories

But since I don’t have any executables called svr and `cnt the problem I am having isn’t solved.

If I change the target to ./client/client.out instead of cnt and then call make client/client.out then it would be fine, exactly what I need but I don’t want to enter long command make client/client.out in my terminal

The workaround I have got is as follows

cnt: $(CLI)
         cc $(FLAGS) $(CLI) -o cnt
         cp cnt ./client/client.out

But not quite satisfied with it. I’m sure what I want to do is really simple and there should be some convenient way around doing it. So how can I do that?

  • 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-12T10:05:48+00:00Added an answer on May 12, 2026 at 10:05 am

    Let’s formulate what you want. You want target named `cnt’ not to be rebuilt. The makefile you’ve written knows nothing about client.out file, because it only appears in shell commands within a rule. Make program doesn’t read information from shell commands, it only does substitutions there and executes them.

    When makefile chooses the targets it will rebuild (`cnt’ is one of these targets), it compares update time of a target file with update time of its prerequsites. Since at the time you run “make cnt” the file named cnt is absent, the target named so is considered as requiring update. So commands are run and yield no file named cnt, so next make run will consider it for updating as well.

    There are two possible solutions. The first one is to give targets same names as of the file, that the rule commands will generate. So, you might end up like this:

    client/client.out: $(CLI)
        cc $(FLAGS) $(CLI) -o ./client/client.out
    

    Your questioin has nothing to do with directories, by the way. You should also read about .PHONY directive, use $(CC) instead of cc and read gnu make manual, which might be very helpful.

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

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • 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 Categories extend the original class, but they don't subclass it,… May 12, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer Haven't tested this, but it's something like: RewriteRule \.php$ -… May 12, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer "0:0:0:0:0:0:0:1" is the IPv6 loopback address as defined in RFC… May 12, 2026 at 12:54 pm

Related Questions

I have a class with a static method that looks roughly like: class X
So, I have a .NET solution that uses StructureMap, and I'd like to have
So I have a django project I just created called 'coolprojectsite' the directory structure
I have a project in Xcode and some resources for the project. The resources
I have a WPF application which saves its data to XML files in a

Trending Tags

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

Top Members

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.