VPATH在makefile问题 [英] VPATH in makefile issue

查看:94
本文介绍了VPATH在makefile问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与VPATH有关的问题. 我在玩make文件和VPATH变量.基本上,我是从几个不同的地方(由VPATH指定)获取源文件,并尝试仅使用所需的.o文件列表将它们编译到另一个目录($ CURDIR/OBJ/)中. /p>

使用VPATH时,我可以在当前目录以外的其他任何目录中创建.o吗?

解决方案

是的,但是您的问题不太正确.

Make擅长在的地方找到东西,并用它们在这里制造东西,但反之则不行. VPATH和vpath告诉make在哪里寻找它需要的东西,但是没有相应的指令将它制造的东西放在当前目录之外.

如果您希望目标文件(OBJECTS = ant.o bee.o)进入$(OBJDIR)之类的另一个目录,则基本上可以通过三种方法来实现.

  1. 在这里建造它们并用手移动它们(几乎可以肯定会给您带来麻烦):

    $(OBJECTS): %.o: %.c
        gcc -c $< -o $@
        mv $@ $(OBJDIR)
    

    或等效地,去那里建造它们:

    $(OBJECTS): %.o: %.c
        cd $(OBJDIR) ; gcc -c $< -o $@
    

  2. 指定路径并将其构建在适当的位置(可能是最适合初学者的路径):

    FULLOBJECTS = $(addprefix $(OBJDIR)/,$(OBJECTS))
    $(FULLOBJECTS): $(OBJDIR)/%.o: %.c
        gcc -c $< -o $@
    

  3. 致电在那里"(功能强大,但非常棘手):

    $(OBJECTS):
        $(MAKE) -C $(OBJDIR) $@
    

I have a question related to VPATH. I'm playing around with make files and the VPATH variable. Basically, I'm grabbing source files from a few different places (specified by the VPATH), and trying to compile them into the another directory ( $CURDIR/OBJ/ ) using simply a list of .o-files that I want.

Can I create .o's in any another directory other than current dir when using VPATH??

解决方案

Well, yes, but your question isn't quite right.

Make is good at finding things there and using them to make things here, but not the other way around. VPATH and vpath tell make where to look for the things it needs, but there is no corresponding directive to put the things it makes somewhere other than the current directory.

If you want your object files (OBJECTS = ant.o bee.o) to go into another directory like $(OBJDIR), there are basically three ways to do it.

  1. Build them here and move them by hand (this one will almost certainly get you in trouble):

    $(OBJECTS): %.o: %.c
        gcc -c $< -o $@
        mv $@ $(OBJDIR)
    

    or equivalently, go there and build them:

    $(OBJECTS): %.o: %.c
        cd $(OBJDIR) ; gcc -c $< -o $@
    

  2. Specify the path and build them in place (probably the best for a beginner):

    FULLOBJECTS = $(addprefix $(OBJDIR)/,$(OBJECTS))
    $(FULLOBJECTS): $(OBJDIR)/%.o: %.c
        gcc -c $< -o $@
    

  3. Call Make there (powerful, but very tricky):

    $(OBJECTS):
        $(MAKE) -C $(OBJDIR) $@
    

这篇关于VPATH在makefile问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆