LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-10-2004, 09:56 PM   #1
chuanyung
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Rep: Reputation: 15
Question [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.
 
Old 03-11-2004, 01:28 AM   #2
chewysplace
Member
 
Registered: Sep 2003
Distribution: Slackware 10 w/ Kernel 2.6.8
Posts: 176

Rep: Reputation: 30
no you just need to make shure you have a target pointed to the main directory that holds all your headers if its not in your lo.so.conf file. if the headers are in the same directory dont worry about it.
 
Old 03-11-2004, 09:22 PM   #3
chuanyung
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Original Poster
Rep: Reputation: 15
hmm...........
Most of these headers are in some directory,said include.
In my first makefile, if I don't give the target "export.h",
make can't run it.

But in my second makefile, I don't need to set the targets,
such as export.h,MainConst.h,trace.h,....
Isn't it so strange?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
makefile targets dand Programming 1 07-11-2005 03:28 PM
tinkering with dkms: make error no targets. Makefile issue? Emmanuel_uk Linux - Newbie 1 06-03-2005 01:26 AM
"no targets specified and no makefile found" liljhand Linux - Software 9 01-01-2005 12:54 PM
How to write Makefile in 2.6 for including header files in another dir ? ashbalu Programming 0 10-19-2004 03:45 PM
Creating a Makefile with multiple header files MattG1981 Programming 4 07-28-2004 05:04 PM


All times are GMT -5. The time now is 03:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration