So I have an assignment where I am supposed to create an oop that will run on a provided Unix server.
I have a Mac so when I run the makefile in Terminal, I don't get any errors. But when I try to run the makefile in the provided Unix server, I get this error:

make: *** No rule to make target `Horse.cpp', needed by `Horse.o'.  Stop.

So can someone explain or show me what I am doing wrong? Here are the contents of the makefile:

horserace: Horse.o Race.o main.o
    g++ Horse.o Race.o main.o -o horserace
main.o: main.cpp Race.h Horse.h
    g++ -c main.cpp Horse.cpp Race.cpp
Horse.o: Horse.cpp Horse.h
    g++ -c Horse.cpp
Race.o: Race.cpp Race.h Horse.h
    g++ -c Race.cpp
clean:
    rm -rf *.o horserace

Any help will be most appreciated.

-Mike

Dani AI

Generated

The error "No rule to make target Horse.cpp', needed byHorse.o'." means make was asked to build an object but couldn't find the matching source file or a rule to produce it. On many Macs the filesystem is case‑insensitive (case‑preserving), so horse.cpp and Horse.cpp can both be opened locally; most Unix/Linux servers are case‑sensitive, so a capitalization mismatch will fail there. As later confirmed, a filename capitalization mismatch was the root cause; 's request to list the directory was the right first diagnostic step.

Useful diagnostics and common pitfalls: verify the working directory and listing with pwd and ls -al; reveal non‑printable characters with ls -b or inspect bytes using hexdump -C/od -c; check for Windows CRLFs in files (the file command or dos2unix can help). Makefile command lines must begin with a literal tab, not spaces — missing tabs produce different, often confusing errors. For visibility into make's decision process, use make -n (dry run) or make -d (verbose debug output). If the server uses a different make implementation, try gmake if available.

A minimal, robust pattern-based Makefile reduces typing mistakes (tabs required before commands):

CXX = g++
CXXFLAGS = -Wall -g
SRCS = Horse.cpp Race.cpp main.cpp
OBJS = $(SRCS:.cpp=.o)
TARGET = horserace

$(TARGET): $(OBJS)
    $(CXX) $(CXXFLAGS) -o $@ $(OBJS)

%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@

clean:
    rm -f $(OBJS) $(TARGET)

Final notes: prefer consistent, simple naming (lowercase helps avoid cross‑platform surprises), test builds on the target server early, and run the basic ls/pwd checks suggested by before deeper debugging. The case‑sensitivity mismatch between development and deployment environments is a very common source of this exact make error.

Recommended Answers

All 4 Replies

It means that Horse.cpp is not present (at least, in the directory where you run make). What does the ls output look like?

make: *** No rule to make target Horse.cpp', needed byHorse.o'. Stop.

I had to emphasize that ls (ell-es) is a command. Run it in the directory whe you run make, and post the output here.

It turns out that I had the capitalization wrong. It is working fine now. Thanks for the info though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.