我试图运行这个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
答案 0 :(得分:0)
小心放置文件的位置。您需要告诉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时才有效。