这是参考第二个回复: How to generate a Makefile with source in sub-directories using just one makefile
除了调用make规则时,解决方案对我很有用。由于文件尚未存在于构建目录中,因此它们似乎永远不会创建任何一个make-goal。我通过在构建目录中创建空文件(只是anyting.o)来测试这个,然后找到make规则
我的结论是%通配符仅查找目录中的内容,并且无法找到该文件,因此它不会为其创建构建规则,因此无法继续。有两种可能的解决方案:
1)找到一种方法来制作在编译器实际启动时被覆盖的虚拟对象文件
2)make make"实现"通配符用于放入make-goal功能的任何内容,而不是目录中的内容
任何指针?
据我所知,我是第一个遇到这个问题的人 \
MODULES := calibration calibration/settings camera/nikon camera ommon
SRC_DIR := $(addprefix src/, $(MODULES)) src
SDK_INCLUDES := include $(addprefix include/, $(MODULES))
BUILD_DIR := build $(addprefix build/, $(MODULES))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
OBJ := $(patsubst src/%.cpp,build/%.o, $(SRC))
# OpenCV directories, change according to your own installation
CV_INCLUDE_DIR = C:\Users\a0225122\Downloads\opencv\build\include
CV_LIB_DIR = C:\Users\a0225122\Downloads\opencv\bin\lib
CV_LIBS = -llibopencv_core249 \
-llibopencv_highgui249 \
-llibopencv_imgproc249 \
-llibopencv_features2d249 \
-llibopencv_calib3d249
CV_FLAGS = -I$(CV_INCLUDE_DIR) -L$(CV_LIB_DIR) $(CV_LIBS)
HID_API_INCLUDE_DIR := 3rd_party/hidapi-master/hidapi/hid.h
# Compiler instructions
CXXFLAGS = -std=c++11 -Wall -I $(SDK_INCLUDE_DIR) -I $(CV_INCLUDE_DIR) -I $(HID_API_INCLUDE_DIR) -L $(CV_LIB_DIR) $(CV_LIBS) -L $(FLYCAP_LIB_DIR) $(FLYCAP_LIBS)
# Clean up instructions
ifdef SystemRoot #This is windows
CXX = mingw32-g++
RM = del /Q
FixPath = $(subst /,\,$1)
BUILD_DIR := $(call FixPath, $(BUILD_DIR))
SRC_DIR := $(call FixPath, $(SRC_DIR))
SDK_INCLUDES := $(call FixPath, $(SDK_INCLUDES))
SRC := $(call FixPath, $(SRC))
OBJ := $(call FixPath, $(OBJ))
CXXFLAGS := $(call FixPath, $(CV_FLAGS))
define make-goal
$1\%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $$< -o $$@
endef
else #more ifeqs can be added for more OS's but this should be fine
CXX = g++
RM = rm -f
define make-goal
$(1)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $$< -o $$@
endef
endif
vpath %.cpp $(SRC_DIR)
SDK_LIBS = lib_core.a
default: SDK.exe
.PHONY: clean
clean:
$(RM) build *.a
#executable generation
SDK.exe: $(SDK_LIBS)
$(CXX) $(CXXFLAGS) $^ -o $@
lib_core.a: checkdirs $(OBJ)
ar rcs lib_core.a $(OBJ)
checkdirs: $(BUILD_DIR)
$(BUILD_DIR):
mkdir $@
#$(OBJ): $(SRC)
# $(CXX) $(CXXFLAGS) -c $^ -o $@
$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir))))
答案 0 :(得分:1)
你的第一个问题是你不能在GNU make规则中使用反斜杠,除了配方(make只是将配方发送到shell,它不解释除$
之外的配方)。所有GNU make目标,先决条件等都必须始终使用正斜杠,即使在Windows上也是如此。
几乎所有Windows应用程序都会正确地接受正斜杠作为目录分隔符。对于少数没有的人,你可以使用你的函数FixPath
,但是你必须在配方中使用它,而不是在目标或先决条件列表中使用它。
如果您仍然遇到问题,一旦解决了该问题,请发布您所拥有的内容,我们会发现。