My question is about compiling error on linux. Every time I try to compile the program it gives me this error. I tried different things without luck.
*** No rule to make target '/pthread.d', needed by '/thread.exe'. Stop.
The makefile for the program ( pthread is as follow:
SOURCES=pthread.cpp
OBJECTS=$(addprefix $(BUILD_DIR)/, $(SOURCES:.cpp=.o))
DEPS=$(addprefix $(BUILD_DIR)/, $(SOURCES:.cpp=.d))
EXE=thread.exe
CXXFLAGS=-I.
LIBS=-pthread
//Making for host > make ARCH=host
ifeq ($(ARCH),host)
CXX=g++
BUILD_DIR=build/host
BIN_DIR=bin/host
endif
//Making for target > make ARCH= target
ifeq ($(ARCH),target)
CXX=arm-rpizw-g++
BUILD_DIR=build/target
BIN_DIR=bin/target
endif
all: $(BIN_DIR)/$(EXE)
$(BIN_DIR)/$(EXE): $(DEPS) $(OBJECTS)
mkdir -p $(BIN_DIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJECTS)
$(BUILD_DIR)/%.d: %.cpp
mkdir -p $(BUILD_DIR)
$(CXX) -MT$(@:.d=.o) -MM $(CXXFLAGS) $^ > $@
$(BUILD_DIR)/%.o: %.cpp
mkdir -p $(BUILD_DIR)
$(CXX) -c $< -o $@ $(CXXFLAGS)
ifneq ($(MAKECMDGOALS), $(filter $(MAKECMDGOALS),clean help))
-include $(DEPS)
endif
clean:
-rm -rf bin/
-rm -rf build/
You likely have spaces after BUILD_DIR=build/target
. Thus, $(DEPS)
resolves to:
build/target /pthread.d
..., and thus make will try to make /pthread.d
(and build/target
...). When assigning a value, make discards any preceding spaces, but not trailing spaces. It will drop a trailing comment, but it will not drop whitespace between the end of the line and the comment.
For debugging this type of problem, it's often useful to add $(info)
lines into your makefile as so:
$(info DEPS=_$(DEPS)_)
and then run to see if there are any unexpected values.