[makefile] Do header files need to be set targets?
Dear all,
I am confused about two makefiles.
I think I write them same way.
But one of them,a header file (export.h) needs to be set a target, then works.
So strange.
Another question is in the second makefile,
I have a static library libUtility.a,
If I add it to:
test: test.o libMEBESStream.so libMEBESDecoder.so libUtility.a
$(CXX) $(CXXFLAGS) $(LIBRARY_PATH) -o $@ $^
It'll appears no rule of target libUtility.a.
If I remove this static library,
the test program is still work the functions in this static library.
I just include his header (Utility.h), then OK.
Why? Don't I link it?
I don't know the second makefile is right or not.
Their relations are:
libMEBESStream.so needs libUtility.a.
libMEBESDecoder.so nees libUtility.a and libMEBESStream.so.
test nees libUtility.a,libMEBESStream.so,and libMEBESDecoder.so.
Are my rules right?
Thanks for your answer.
first:
----------------------------------------------------------------------------
SHELL = /bin/sh
CXX = g++
INCLUDE_PATH = -I. -I../include
LIBRARY_PATH = -L.
COMMON_HEADER = export.h
CXXFLAGS = -fPIC -O3 -Wno-deprecated
PLATFORM = xnix
test: test.o libCheckFileFormat.so
$(CXX) $(CXXFLAGS) $(LIBRARY_PATH) -lCheckFileFormat \
-o $@ $^
test.o: test.cpp CheckFileFormat.h
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c -o $@ $<
libCheckFileFormat.so: CheckFileFormat.o
$(CXX) $(CXXFLAGS) -shared -o $@ $<
CheckFileFormat.o: CheckFileFormat.cpp CheckFileFormat.h \
$(COMMON_HEADER)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c -o $@ $<
#####################################
export.h:; ### <--- I need to set it,then works
#####################################
clean:
rm -rf *.o
----------------------------------------------------------------------------------
second
----------------------------------------------------------------------------------
SHELL = /bin/sh
CXX = g++
INCLUDE_PATH = -I. -I../include -I../Utility
LIBRARY_PATH = -L. -L../Utility
SHARED_LIBRARY = libMEBESStream.so libMEBESDecoder.so
STATIC_LIBRARY = libUtility.a
COMMOM_HEADER = MainConst.h export.h trace.h patternFactory.h Utility.h MEBESConst.h
CXXFLAGS = -fPIC -O3 -Wno-deprecated
PLATFORM = xnix
test: test.o libMEBESStream.so libMEBESDecoder.so
$(CXX) $(CXXFLAGS) $(LIBRARY_PATH) -o $@ $^
test.o: test.cpp $(COMMON_HEADER)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c -o $@ $<
libMEBESDecoder.so: MEBESDecoder.o
$(CXX) $(CXXFLAGS) -shared -o $@ $^
MEBESDecoder.o:MEBESDecoder.cppBESDecoder.h \
MEBESStream.h$(COMMON_HEADER)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c -o $@ $<
libMEBESStream.so: MEBESStream.o
$(CXX) $(CXXFLAGS) -shared -o $@ $<
MEBESStream.o: MEBESStream.cpp MEBESStream.h $(COMMON_HEADER)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c -o $@ $<
clean:
rm -rf *.o
--------------------------------------------------------------------------------------------
Regards,
chuanyung.
|