【问题标题】:Makefile: "No rule to make target..." with multiple working directoriesMakefile:“没有规则来制作目标......”具有多个工作目录
【发布时间】:2016-06-02 20:58:40
【问题描述】:

我正在尝试运行此 makefile,但遇到了问题。让我告诉我

"No rule to make target 'UDP_Server.o', needed by 'SendRawData',

既然我已经给了它文件的工作目录,那么 %.o 文件的规则不应该正常工作吗?我在 /thing/asset/src 目录中启动 make,我不在乎它把 o 文件或程序放在哪里,只要我可以访问它们。这是我的生成文件:

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

【问题讨论】:

  • 你给了一个makefile,但是你的树说你有多个,是哪一个?
  • 你在哪里执行 Make?你希望它把二进制文件放在哪里(例如UDP_Client.oSendRawData)?
  • 改变了,好点。

标签: c++ c compilation compiler-errors makefile


【解决方案1】:

请注意您放置文件的位置。你需要告诉 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 时才有效。

【讨论】:

    猜你喜欢
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多