[英]Makefile: “No rule to make target…” with multiple working directories
我正在尝试运行此makefile,并遇到问题。 告诉我
"No rule to make target 'UDP_Server.o', needed by 'SendRawData',
既然我已经给它了文件的工作目录,那么%.o文件的规则不应该正常工作吗? 我在/ thing / asset / src目录中启动make,并且我不关心它放置o文件或程序的位置,只要我可以访问它们。 这是我的makefile:
CC = g++
INC += -I/home/pi/thing/
INC += -I/home/pi/thing/Asset/src/
INC += -I/home/pi/thing/Server/src/
INC += -I/home/pi/thing/Shared/NetworkInterface/src/
INC += -I/home/pi/mercuryapi/c/src/
LIB = /home/pi/mercury/c/src/api/
CFLAGS = -std=c++11 -Wno-write-strings
LDFLAGS = -L$(LIB) -static -l libmercuryapi
SOURCES += UDP_Client.cpp
SOURCES += UDP_Server.cpp
SOURCES += rawData.cpp
SOURCES += packetMethods.cpp
SOURCES += parseData.cpp
SOURCES += SendRawData.cpp
OBJECTS = $(SOURCES:.cpp=.o)
DEPS = UDP_Client.h
DEPS += UDP_Server.h
DEPS += packet.h
DEPS += rawData.h
DEPS += packetMethods.h
DEPS += parseData.h
DEPS += tm_reader.h
default: SendRawData
%.o: %.cpp $(SOURCES) $(DEPS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
SendRawData: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) $(INC) $< -o SendRawData
client: cmain.cpp UDP_Client.cpp
$(CC) $(CFLAGS) cmain.cpp UDP_Client.cpp -o client
.cpp.o:
$(CC) $(CFLAGS) $(INC) -c $< -o $@
.PHONY: clean
clean:
rm *.o
如果它有帮助,这里是可视化的目录结构:
/home/pi/thing/
├── Asset
│ ├── README.txt
│ └── src
│ ├── makefile
│ ├── README.txt
│ ├── SendRawData.cpp
│ ├── UDP_Client.cpp
│ └── UDP_Client.h
├── Server
│ └── src
│ ├── README.txt
│ ├── server
│ ├── UDP_Server.cpp
│ ├── UDP_Server.h
│ └── UDP_Server.o
└── Shared
├── NetworkInterface
│ ├── README.txt
│ └── src
│ ├── header.h
│ ├── packet.h
│ ├── packetMethods.cpp
│ ├── packetMethods.h
│ ├── parseData.cpp
│ ├── parseData.h
│ ├── rawData.cpp
│ ├── rawData.h
│ └── testing.cpp
└── README.txt
小心放置文件的位置。 您需要告诉make源文件的位置。
丑陋,乏味但解释性的解决方案是在指定依赖项时添加路径。 代替
SOURCES += UDP_Client.cpp
写
SOURCES += ../../Server/src/UDP_Client.cpp
美丽而简单的解决方案是使用make VPATH变量:
https://www.gnu.org/software/make/manual/html_node/General-Search.html
例如
VPATH = "../../Server/src/UDP_Client.cpp:<list of : separated paths>"
此解决方案可能仅在您使用gnu make时才有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.