我的Makefile不断告诉我

make: *** No rule to make target `rs232.c',


我在这里列出了文件(rs232.c位于最后)-

SOURCES_RAW=codeprofiler.cpp gametimer.cpp timer.cpp timeprofile.cpp vector4.cpp matrix.cpp agent.cpp agentcontroller.cpp dummy.cpp evader.cpp pursuer.cpp goal.cpp player.cpp graphdata.cpp graph.cpp cubiccoefs.cpp segment.cpp trajectory.cpp anode.cpp arrayvector4.cpp color.cpp drawcomponent.cpp drawcontroller.cpp flags.cpp global.cpp map_analyzer.cpp minheap.cpp node.cpp quadtree.cpp queue.cpp results.cpp sensor.cpp settings.cpp utility.cpp world.cpp gui.cpp main.cpp logger.cpp parameters.cpp counter.cpp polygon.cpp line.cpp robot_driver_agent.cpp position.cpp robot_driver_priorityqueue.cpp main.cpp robot_driver_tree.cpp robot_driver_grid.cpp path.cpp tcpserver.cpp tcpclient.cpp servercontrol.cpp clientcontrol.cpp Robot.cpp udpserver.cpp udpclient.cpp rs232.c


所有这些文件都在一个名为src的文件夹中。所以我-

SRCDIR= src
SOURCES:=$(SOURCES_RAW)
SOURCES:=$(patsubst %.c, $(SRCDIR)/%.c, $(SOURCES))
SOURCES:=$(patsubst %.cpp, $(SRCDIR)/%.cpp, $(SOURCES))


为什么不编译.c文件?

整个Makefile是-

INCLUDE = -I/usr/X11R6/include
#INCLUDE_W32 = -Isrc
CC=g++
CFLAGS=-w -D LINUX -fpermissive
CFLAGS_R= -w -D LINUX -O3 -fpermissive
CFLAGS_D=-w -D LINUX -fpermissive
OBJ= obj
OBJ_DEBUG= obj_debug
OBJDIR= release
SRCDIR= src

LDFLAGS= -L/usr/X11R6/lib$(LIBSELECT) -lGL -lfltk -lfltk_gl -lXext -lX11 -lglut -lGLU -lfltk_images

SOURCES_RAW=codeprofiler.cpp gametimer.cpp timer.cpp timeprofile.cpp vector4.cpp matrix.cpp agent.cpp agentcontroller.cpp dummy.cpp evader.cpp pursuer.cpp goal.cpp player.cpp graphdata.cpp graph.cpp cubiccoefs.cpp segment.cpp trajectory.cpp anode.cpp arrayvector4.cpp color.cpp drawcomponent.cpp drawcontroller.cpp flags.cpp global.cpp map_analyzer.cpp minheap.cpp node.cpp quadtree.cpp queue.cpp results.cpp sensor.cpp settings.cpp utility.cpp world.cpp gui.cpp main.cpp logger.cpp parameters.cpp counter.cpp polygon.cpp line.cpp robot_driver_agent.cpp position.cpp robot_driver_priorityqueue.cpp main.cpp robot_driver_tree.cpp robot_driver_grid.cpp path.cpp tcpserver.cpp tcpclient.cpp servercontrol.cpp clientcontrol.cpp Robot.cpp udpserver.cpp udpclient.cpp rs232.c

TARGET:= pursuit_evasion
TARGETD:= pursuit_evasion_d
TARGETP:= pursuit_evasion_p
TARGETW32:= pursuit_evasion_w32

OBJECTS:=$(SOURCES_RAW:.cpp=.o)
OBJECTS:=$(patsubst %.o,$(OBJDIR)/%.o, $(OBJECTS))

SOURCES:=$(SOURCES_RAW)
SOURCES:=$(patsubst %.cpp, $(SRCDIR)/%.cpp, $(SOURCES))

OBJ_DEBUG:=$(SOURCES_RAW:.cpp=.o)
OBJ_DEBUG:=$(patsubst %.o,debug/%.o, $(OBJ_DEBUG))

OBJECTS_P:=$(SOURCES_RAW:.cpp=.o)
OBJECTS_P:=$(patsubst %.o,profile/%.o, $(OBJECTS_P))

OBJDIR=obj

all: $(TARGET)

#--- Release
$(TARGET): $(OBJECTS)
    $(CC) -w -D LINUX $(INCLUDE) $^ -o $@ $(LDFLAGS)

release/%.o: src/%.cpp
    $(CC) -c $< $(CFLAGS_R) -o $@

#--- Debug
debug: $(TARGETD)

$(TARGETD): $(OBJ_DEBUG)
    $(CC) -w -D LINUX $(INCLUDE) $^ -o $@ $(LDFLAGS)

debug/%.o: src/%.cpp
    $(CC) -c -g $< $(CFLAGS)-o $@

#-- Profile
profile: $(TARGETP)

$(TARGETP): $(OBJECTS_P)
    $(CC) -w -g -pg -D LINUX $(INCLUDE) $^ -o $@ $(LDFLAGS)

profile/%.o: src/%.cpp
    $(CC) -c -g -pg $< $(CFLAGS)-o $@

win32: $(TARGETW32)

$(TARGETW32): $(OBJECTS)
    $(CC) -w -D WIN32 $(INCLUDE_W32) $^ -o $@ $(LDFLAGS)

.PHONY : clean
clean:
    rm -f release/*.o
    rm -f debug/*.o
    rm -f profile/*.o
    rm -f $(TARGET) $(TARGETD) $(TARGETP)

最佳答案

您以前的所有文件(在rs232.c之前)实际上都是C ++文件。

我猜您在以后的makefile中有一个编译C ++文件的规则,但是您是否也有一个编译纯C文件的规则?

喜欢:

%.o: %.c
    gcc [...]


编辑-只为您知道

您不必指定所有要编译的文件。

看一下foreachdir函数。
这样,您就可以从目录中获取与特定模式匹配的所有文件。

例:

FILES = $(foreach dir,$(DIR_SRC),$(wildcard $(DIR_SRC)*.cpp))

08-26 20:12
查看更多