0

I've edited the pset6 Makefile to include all headers, and was careful not to edit any spaces or tabs. When I try to compile speller, I get the following error:

make: *** No rule to make target `math.h`, needed by `speller.o`. Stop. 

Do I have to pull math.h into the current directory?

Here is my Makefile:

#
# Makefile
#
# Computer Science 50
# Problem Set 6
#


# compiler to use
CC = clang

# flags to pass compiler
CFLAGS = -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror

# name for executable
EXE = speller

# space-separated list of header files
HDRS = dictionary.h math.h ctype.h string.h stdio.h stdbool.h stdlib.h

# space-separated list of libraries, if any,
# each of which should be prefixed with -l
LIBS =

# space-separated list of source files
SRCS = speller.c dictionary.c

# automatically generated list of object files
OBJS = $(SRCS:.c=.o)


# default target
$(EXE): $(OBJS) $(HDRS) Makefile
    $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

# dependencies 
$(OBJS): $(HDRS) Makefile

# housekeeping
clean:
    rm -f core $(EXE) *.o
1
  • This question appears to be off-topic because it shows a lack of research effort - it's a "please check my code".
    – Tim
    Dec 27 '14 at 21:43
1

Pay attention to these lines in your Makefile:

# space-separated list of libraries, if any,
# each of which should be prefixed with -l
LIBS =

You should add math.h so make knows it needs to link it (as in -lm)

2

I needed to add -lm to the libraries and remove all headers from the Makefile.

# space-separated list of header files
HDRS = dictionary.h 

# space-separated list of libraries, if any,
# each of which should be prefixed with -l
LIBS = -lm

While I was working on my hash function, I found I needed to use <math.h> in order to use exponents, so it was added in my dictionary.c with #include <math.h>. When I tried to find out if it was a header or a library, most sites referred to it as a header, but I remembered -lm from the first Psets and did a search, and found the correct answer.

4
  • I didn't see your answer the minute I was clicking my add answer button, my apologies. Dec 27 '14 at 21:55
  • 1
    actually @Tim if you look closely at the times of both answers you'll see ErinMagner actually answered own question first (by an inch;) (upvoted to compensate)
    – abelinux
    Dec 27 '14 at 21:56
  • @abe @erin oops, my mistake. Retreating dv (but your answer is much better).`
    – Tim
    Dec 27 '14 at 21:57
  • ErinMagner if you worked out your solution, please edit your answer with some more detail and mark it as "accepted", so other people with the same question can benefit from it later on :)
    – abelinux
    Dec 27 '14 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .