我對GNU makefile有一些有限的認識,目前我的失敗了。Makefile中的依賴關係沒有正確考慮
我有一個類聲明文件:mdfTree.h,類mdfTree.cpp的實現和一個mdfTree_x.cpp文件,其中主要是創建類mdfTree的對象並調用其公用函數,然後依次調用它的公共函數調用一些mdfTree的私有成員變量。
我用的Makefile編譯它:
CXX=g++
CXXFLAGS=-g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings $(shell root-config --cflags --gl\
ibs)
LDFLAGS=-g $(shell root-config --ldflags)
LDLIBS=$(shell root-config --libs)
mdfTree_x: mdfTree_x.o
g++ $(LDFLAGS) -o mdfTree_x mdfTree_x.o $(LDLIBS)
mdfTree_x.o: mdfTree_x.cpp
g++ $(LDFLAGS) $(CXXFLAGS) -c mdfTree_x.cpp
mdfTree.cpp和mdfTree_x.cpp中有一個#include mdfTree.h
。 mdfTree_x.cpp是否也需要#include mdfTree.cpp
?
我想我的Makefile是錯誤的,因爲當我嘗試編譯時,類mdfTree的公共函數看不到相同類的私有變量。另外,當我在mdfTree.h中插入一個語法錯誤時,編譯器不會將其提取出來。我如何告訴Makefile mdfTree_x需要使用/編譯mdfTree.h/.cpp?
謝謝,解決了這個問題。 – mareks