这是针对特定案例的更具体的问题。
这就是我所拥有的:
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 $?
当我运行此操作时,我收到以下错误:
make[1]: *** No rule to make target `obj/symb_obj/CartoCursor.o', needed by `libSymbolXLib.a'. Stop.
我需要做些什么才能让libSymbolXLib识别通用构建规则?
如果不清楚,请告诉我。
更新
使用:
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]$
答案 0 :(得分:2)
看起来很像INT_DIR
和$?使用的变量不合适。我期待这个:
$(SYMB_OBJ_DIR)/%.o : %.cpp
$(CXX) -c $(CC_FLAGS) $(SYMB_X_INCLUDE) -o $@ $<
您还希望将libSymbolXLib.a的ar规则更新为rm
以外的其他内容:)
以下示例在我的系统上运行良好:
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)
ar rcs $@ $^
$(SYMB_OBJ_DIR)/%.o : %.cpp
$(CXX) -c $(CC_FLAGS) $(SYMB_X_INCLUDE) -o $@ $<
演示:
$
touch CartoCursor.cpp CartoOperatorFactory.cpp CurveHelper.cpp
$mkdir -pv obj/symb_obj
$make
g++ -c -fPIC -Wall -I../../../MYLIBS -o obj/symb_obj/CartoCursor.o CartoCursor.cpp g++ -c -fPIC -Wall -I../../../MYLIBS -o obj/symb_obj/CartoOperatorFactory.o CartoOperatorFactory.cpp g++ -c -fPIC -Wall -I../../../MYLIBS -o obj/symb_obj/CurveHelper.o CurveHelper.cpp ar rcs libSymbolXLib.a obj/symb_obj/CartoCursor.o obj/symb_obj/CartoOperatorFactory.o obj/symb_obj/CurveHelper.o
$
file libSymbolXLib.a
libSymbolXLib.a: current ar archive
答案 1 :(得分:1)
确保运行Make的目录中存在CartoCursor.cpp
。
同样相对于Paul's Rules of Makefiles,您应修改$(SYMB_OBJ_DIR)/%.o : %.cpp
的配方,以使用目标的确切名称更新文件,即:
$(SYMB_OBJ_DIR)/%.o : %.cpp
$(CXX) -c $(CC_FLAGS) $(SYMB_X_INCLUDE) -o $@ $^
同样适用于libSymbolXLib.a
的配方,它必须更新目标文件。您可以插入touch $@
存根进行调试,或者@sehe mentioned添加正确的食谱:
libSymbolXLib.a : $(SYMB_X_OBJS)
ar rcs $@ $^