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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:07:08+00:00 2026-06-17T18:07:08+00:00

I have this Makefile : CFLAGS := $(CFLAGS) -std=c99 shell: main.o shellparser.o shellscanner.o $(CC)

  • 0

I have this Makefile:

CFLAGS := $(CFLAGS) -std=c99

shell: main.o shellparser.o shellscanner.o
    $(CC) -o shell main.o shellparser.o shellscanner.o

main.o: main.c shellparser.h shellscanner.h

shellparser.o: shellparser.h

shellparser.h: shellparser.y lemon
    ./lemon shellparser.y

shellscanner.o: shellscanner.h

shellscanner.h: shellscanner.l
    flex --outfile=shellscanner.c --header-file=shellscanner.h shellscanner.l

# Prevent yacc from trying to build parsers.
# http://stackoverflow.com/a/5395195/79202
%.c: %.y

lemon: lemon.c
    $(CC) -o lemon lemon.c

For some reason, on the first run of make, shellparser.o isn’t built:

> make
cc -o lemon lemon.c
./lemon shellparser.y
flex --outfile=shellscanner.c --header-file=shellscanner.h shellscanner.l
cc  -std=c99   -c -o main.o main.c
cc  -std=c99   -c -o shellscanner.o shellscanner.c
cc -o shell main.o shellparser.o shellscanner.o
i686-apple-darwin10-gcc-4.2.1: shellparser.o: No such file or directory
make: *** [shell] Error 1
rm shellscanner.c

If I run it again, it then builds it correctly:

> make
cc  -std=c99   -c -o shellparser.o shellparser.c
cc -o shell main.o shellparser.o shellscanner.o

So what do I have out-of-order such that it doesn’t build it the first time?

  • 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-17T18:07:09+00:00Added an answer on June 17, 2026 at 6:07 pm

    The first time you try to build, Make doesn’t know that lemon outputs shellparser.c, so it doesn’t try to build it. When you rebuild, shellparser.c does exist, so Make uses it. The solution is to explicitly tell Make that lemon outputs shellparser.c:

    diff --git a/Makefile b/Makefile
    index bf2655e..d6b288d 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -7,7 +7,7 @@ main.o: main.c shellparser.h shellscanner.h
    
     shellparser.o: shellparser.h
    
    -shellparser.h: shellparser.y lemon
    +shellparser.c shellparser.h: shellparser.y lemon
            ./lemon shellparser.y
    
     shellscanner.o: shellscanner.h
    diff --git a/main.c b/main.c
    index 81ec151..4179981 100644
    --- a/main.c
    +++ b/main.c
    @@ -33,7 +33,7 @@ void parse(const char *commandLine) {
     }
    
     // Borrowed from http://stackoverflow.com/a/314422/79202.
    -char * getline(void) {
    +char * my_getline(void) {
         char * line = malloc(100), * linep = line;
         size_t lenmax = 100, len = lenmax;
         int c;
    @@ -69,7 +69,7 @@ int main(int argc, char** argv) {
         void* shellParser = ParseAlloc(malloc);
         char *line;
         printf("> ");
    -    while ( line = getline() ) {
    +    while ( line = my_getline() ) {
             parse(line);
             printf("> ");
         }
    

    Also I renamed getline so it would build on my mac; thanks for posting all your source!

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

Sidebar

Related Questions

I have this makefile: SHELL=/bin/zsh COMPILER=g++ -g COMPILERSO=g++ -a +a1 -b LIBDIR=/Users/romeovs/Desktop/rootex CFLAGS=$(root-config --cflags)
So, this is odd. In my makefile I have CC:=icc ifeq ($(CC),icc) CFLAGS :=
I have this simple rule in my Makefile : PP=g++ -std=c++0x %.o: $.cpp $(PP)
I have this in my Makefile: %.x: %.c $(CC) $(CFLAGS) -o $@ $^ So
I am in linux. My Makefile file is this main2: main.cpp g++ -c $(LIBS)
I have main.c, snmpy.c, snmpy.o, and a makefile. I running this on a Linux
I have a C makefile which generates header file from java code and compiles
I have this in my makefile test: cat t.txt | sort -t $$'\t' -k
At the beginning of a makefile I have this line : PATH := $(PATH):/other/dir
I have a source directory which uses makefile to compile the code. This makefile/configure

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.