使用 make 生成依赖项时出错
Error generating dependencies with make
我正在尝试实现论文"递归使被认为是有害的"中概述的非递归使解决方案。我目前坚持要生成的 *.d 依赖项文件。我在下面提供了生成文件、示例 module.mk 和错误。任何想法如何解决这个问题?
MODULES :=
module1
module2
# define compiler
CC = /opt/local/bin/clang++-mp-3.1
# exclude the following warnings for clang
CLANG_NO_WARN =
-Wno-c++98-compat
-Wno-weak-vtables
-Wno-padded
-Wno-global-constructors
-Wno-exit-time-destructors
# look for include files in each of the modules
CFLAGS +=
-g -Weverything -Wall -std=c++11 -stdlib=libc++ $(CLANG_NO_WARN)
-I../ -I/usr/local/include $(patsubst %, -I%, $(MODULES))
# linker flags
LDFLAGS :=
-stdlib=libc++
-L/usr/local/boost_1_50_0/stage/lib -L/usr/local/lib
# extra libraries if required (each module will add to this)
LIBS :=
-lboost_program_options
-lboost_system
-lglog
-lpugixml
# source files to be compiled (each module will add to this)
SRCS :=
Main.cpp
# include the descriptions for each module
include $(patsubst %, %/module.mk, $(MODULES))
# determine the object files
OBJS :=
$(patsubst %.cpp, %.o, $(filter %.cpp, $(SRCS)))
# link the program
prog: $(OBJS)
$(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
# include the C include dependencies
include $(OBJS:.o=.d)
# calculate C include dependencies
%.d: %.cpp
depend.sh `dirname $*.cpp` $(CFLAGS) $*.cpp > $@
----------
#!/bin/sh
# Evaluate dependencies for use by the makefile
echo "Called"
DIR="$1"
shift 1
case "$DIR" in
"" | ".")
$CC -MM -MG "$@" | sed -e 's@ˆ(.*).o:@1.d 1.o:@' ;;
*)
$CC -MM -MG "$@" | sed -e "s@ˆ(.*).o:@$DIR/1.d $DIR/1.o:@" ;;
esac
------------
# module.mk
SRCS +=
Algo.cpp
CommandHandler.cpp
Exchange.cpp
TCPSocket.cpp
TradingEngine.cpp
----------
$ make
makefile:68: Main.d: No such file or directory
makefile:68: view_string.d: No such file or directory
makefile:68: Algo.d: No such file or directory
makefile:68: CommandHandler.d: No such file or directory
makefile:68: Exchange.d: No such file or directory
makefile:68: TCPSocket.d: No such file or directory
makefile:68: TradingEngine.d: No such file or directory
makefile:68: Exchange.d: No such file or directory
makefile:68: Requests.d: No such file or directory
makefile:68: TickCapture.d: No such file or directory
makefile:68: types.d: No such file or directory
make: *** No rule to make target `types.d'. Stop.
更新完成的生成文件和示例 module.mk
$cat makefile
# executable name
BINARY := my_prog
# clang config
CLANG := /opt/local/bin/clang++-mp-3.1
CLANG_WARNINGS :=
-Wno-c++98-compat
-Wno-weak-vtables
-Wno-padded
-Wno-global-constructors
-Wno-exit-time-destructors
CLANG_CFLAGS :=
-g -Weverything -Wall -std=c++11 -stdlib=libc++
CLANG_LDFLAGS :=
-stdlib=libc++
# generic compiler config
CC := $(CLANG)
CFLAGS := $(CLANG_WARNINGS) $(CLANG_CFLAGS)
LDFLAGS := $(CLANG_LDFLAGS)
INCS :=
-I../
-I/usr/local/include
$(patsubst %, -I%, $(SUBDIRS))
LIBS :=
-L/usr/local/boost_1_50_0/stage/lib
-L/usr/local/lib
-lboost_program_options
-lboost_system
-lglog
-lpugixml
# list subdirectories in which to look for dependencies
# must define SRCS first as subdirs will append to this
# their src files
SRCS := Main.cpp
SUBDIRS :=
module1
module2
include $(patsubst %, %/module.mk, $(SUBDIRS))
# derive object files from srcs
OBJS := $(patsubst %.cpp, %.o, $(filter %.cpp, $(SRCS)))
# link the program
$(BINARY): $(OBJS)
$(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
# include generated dependency files
DEPS := $(OBJS:.o=.d)
-include $(DEPS)
# generate include dependencies
%.d: %.cpp
./depend.sh `dirname $*.cpp` $(INCS) $*.cpp > $@
# compile
.cpp.o:
$(CC) $(CFLAGS) $(INCS) $< -c -o $@
# clean, obviously
clean:
rm -f $(BINARY)
rm -f $(OBJS)
rm -f $(DEPS)
# et voila!
-----
$cat module1/module.mk
SRCS_PATH := module1
SRCS +=
$(SRCS_PATH)/Algo.cpp
$(SRCS_PATH)/CommandHandler.cpp
$(SRCS_PATH)/Exchange.cpp
$(SRCS_PATH)/TCPSocket.cpp
$(SRCS_PATH)/TradingEngine.cpp
看起来好像某个模块将types.cpp
添加到SRCS
,即使不存在这样的源文件。
至于警告,第一次运行此makefile时,依赖项文件(foo.d
)尚不存在,因此Make抱怨无法include
它们。这不是问题,当这些文件事先存在时,警告不会出现在后续运行中。要完全取消警告,请将include
更改为 -include
。
相关文章:
- 如何从C++中的依赖类型中获得它所依赖的类型
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 用pybind11包装C++抽象类时出错
- 将依赖名称显式标记为类型名和模板的奇怪之处
- 传递具有依赖嵌套参数类型的模板模板参数时出错
- 使用 make 生成依赖项时出错
- 依赖关系Walker:打开文件时出错
- 在Unity项目中使用依赖于另一个NDK构建的库时出错