GNU make:Makefile一次构建多个.cpp文件 [英] GNU make: Makefile Build Multiple .cpp Files at Once

查看:258
本文介绍了GNU make:Makefile一次构建多个.cpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个特定的问题。

This is more of a specific question on a specific case.

这里是我有的:

SRC = \
  CartoCursor.cpp \
  CartoOperatorFactory.cpp \
  CurveHelper.cpp \
  $(NULL)

CXX = g++
CC_FLAGS = -fPIC -Wall
SYMB_OBJ_DIR = ./obj/symb_obj
SYMB_X_INCLUDE = -I../../../MYLIBS
SYMB_X_OBJS = $(SRC:%.cpp=$(SYMB_OBJ_DIR)/%.o)

all : libSymbolXLib.a

libSymbolXLib.a : $(SYMB_X_OBJS)
        rm -f $@


$(SYMB_OBJ_DIR)/%.o : %.cpp
        $(CXX) -c $(CC_FLAGS) $(SYMB_X_INCLUDE) -o $(INT_DIR)/$*.o $?

当我运行这个我得到以下错误:

When I run this I am getting the following error:

make[1]: *** No rule to make target `obj/symb_obj/CartoCursor.o', needed by `libSymbolXLib.a'.  Stop.

我需要做什么才能让libSymbolXLib识别通用构建规则?

What do I need to do to get the libSymbolXLib to recognize the generic build rule?

如果这还不清楚,请告诉我。

If this is not clear please let me know.

UPDATE

使用:

CXX = g++
CC_FLAGS = -fPIC -Wall
SYMB_OBJ_DIR = ./obj/symb_obj
SYMB_X_INCLUDE = -I../../../MYLIBS
SYMB_X_OBJS = $(SRC:%.cpp=$(SYMB_OBJ_DIR)/%.o)

all : libSymbolXLib.a

libSymbolXLib.a : $(SYMB_X_OBJS)
        ar rcs $@ $^

$(SYMB_OBJ_DIR)/%.o : %.cpp
        $(CXX) -c $(CC_FLAGS) $(SYMB_X_INCLUDE) -o $@ $

[mehoggan@hogganz400 Core]$ make
mkdir -p ./libs
mkdir -p ./obj/symb_obj
make -f ./Graphic/SymbolXLib/Makefile
make[1]: Entering directory `/home/mehoggan/arcgis-new/GraphicsCore_Dev/Runtime/Core'
make[1]: *** No rule to make target `obj/symb_obj/CartoCursor.o', needed by `libSymbolXLib.a'.  Stop.
make[1]: Leaving directory `/home/mehoggan/arcgis-new/GraphicsCore_Dev/Runtime/Core'
make: *** [build_symbol_x_lib] Error 2
[mehoggan@hogganz400 Core]$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-redhat-linux-gnu
[mehoggan@hogganz400 Core]$ uname -a
Linux hogganz400.esri.com 2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
[mehoggan@hogganz400 Core]$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.0 (Santiago)
[mehoggan@hogganz400 Core]$ 


推荐答案

确保 CartoCursor.cpp 存在于运行Make的目录中。

Make sure that CartoCursor.cpp exists in the directory where you run Make.

a href =http://mad-scientist.net/make/rules.html =nofollow> Paul的Makefiles规则,您应该修改 $(SYMB_OBJ_DIR)/ %.o:%.cpp 以使用目标的准确名称更新文件,即:

Also accordingly to Paul's Rules of Makefiles you should modify recipe of $(SYMB_OBJ_DIR)/%.o : %.cpp to update the file with exact name of the target, that is:

$(SYMB_OBJ_DIR)/%.o : %.cpp
    $(CXX) -c $(CC_FLAGS) $(SYMB_X_INCLUDE) -o $@ $^



UPD。



同样适用于 libSymbolXLib.a ,它必须更新目标文件。您可以插入 touch $ @ 存根进行调试,或者@sehe有提到的添加适当的食谱:

UPD.

The same applies to recipe for libSymbolXLib.a, it must update the target file. You can insert a touch $@ stub for debugging, or as @sehe has mentioned add a proper recipe:

libSymbolXLib.a : $(SYMB_X_OBJS)
    ar rcs $@ $^

这篇关于GNU make:Makefile一次构建多个.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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