从茎中的文件名生成 makefile 目标依赖项
您好,我正在创建一个 makefile,其中每个 .o 表示为另一个目录的相对路径,并且依赖于本地目录中的 .cpp 文件。我对问题的理解是,我不能在规则定义中使用函数,因此规则:
%.o: %.cpp
会产生先决条件 .cpp,该 .cpp 与 .o 位于同一目录中,而不是 cpp 所在的目录实际上位于。例如:
../../Tmp/MyClass.o: ../../Tmp/MyClass.cpp <--- 错误,%.o 的结果: %.cpp
../../Tmp/ MyClass.o: MyClass.cpp <--- 对,我如何以自动方式执行此操作?
最后,位于另一个目录中的输出依赖于 .o,因此它们必须从一开始就具有完整的相对路径信息:
OBJS := $(addprefix ../../../Tmp/XCode/ ${PLATFORM}/${CONFIGURATION}/, $(addsuffix .o, $(basename ${SRCS})))
${OUTPUT}: ${OBJS} ; ${AR} $@ ${OBJS}
谢谢!
Hi I have a makefile I am creating where each .o is represented as a relative path to another directory and has a dependency on a .cpp file in the local directory. My understanding of the problem is that I can't use functions in a rule definition so the rule:
%.o: %.cpp
results in a prerequisite .cpp that is in the same directory as the .o which is not where the cpp is actually located. For example:
../../Tmp/MyClass.o: ../../Tmp/MyClass.cpp <--- WRONG, result of %.o: %.cpp
../../Tmp/MyClass.o: MyClass.cpp <--- RIGHT, how do I do this in an automatic way?
Lastly the output, which is in yet another directory, has a dependency on the .o's so they must all have full relative path information from the beginning:
OBJS := $(addprefix ../../../Tmp/XCode/${PLATFORM}/${CONFIGURATION}/, $(addsuffix .o, $(basename ${SRCS})))
${OUTPUT}: ${OBJS} ; ${AR} $@ ${OBJS}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为克里斯蒂的解决方案会起作用,但这是做同样事情的另一种方法:
I think kristi's solution will work, but here's another way to do the same thing:
这应该有效
或者使用变量
This should work
Or use a variable